Python Interview Questions (Part 3)
What is GIL in Python?
The Global Interpreter Lock (GIL) in Python is a mutex that allows only one thread to execute in the interpreter at a time. This affects multi-threaded programs, limiting true parallelism. While it can boost performance for single-threaded tasks, it hinders multi-threaded performance on multi-core systems.
Why was the language called Python?
Python is named after the British comedy group "Monty Python." Guido van Rossum, Python's creator, was a fan of the group. The name reflects the language's focus on readability, humor, and simplicity.
Docstrings vs Comments
Docstrings are used to provide documentation for functions, modules, and classes in Python. Unlike comments, docstrings are accessible at runtime using the . __doc__ attribute. They offer a standardized way of documenting code and can be used to generate documentation automatically.
What are Python decorators?
Decorators in Python are functions that modify other functions or methods. They allow you to add functionality to existing code without modifying it directly. Common use cases include logging, access control, and performance measurement.
Is there a switch..case statement in Python?
Python does not have a built-in switch..case statement like some other programming languages. Instead, you can use a dictionary to simulate switch-like behavior, where keys are cases and values are associated actions.
raw_input() VS. input() in Python?
In Python 2, raw_input() reads input as strings, while input() evaluates the input as Python code. In Python 3, input() reads input as strings, and raw_input() is not available.
What is the difference between Xrange and range?
In Python 2, xrange() generates values one at a time and is more memory-efficient for large ranges, while range() creates a list containing all values at once. In Python 3, range() functions like Python 2's xrange().
How to exit Python script in command prompt?
In the command prompt, you can exit a Python script by typing exit() or pressing Ctrl + Z followed by Enter.
Why is Python not fully object-oriented?
Python is not fully object-oriented because it allows procedural programming and supports non-object-oriented constructs. This flexibility enhances Python's ease of use and adaptability to various programming styles.
When is a dictionary used instead of a list?
Dictionaries are used when you need to store data with key-value pairs, allowing efficient retrieval by keys. Lists are used for ordered collections of items. Dictionaries are better suited for scenarios that require efficient lookups and mappings.
What do you mean by list comprehension?
List comprehension is a concise way to create lists in Python by specifying the elements you want in the list, often with a condition or transformation applied to the elements.
What is the Dogpile effect?
The Dogpile effect, also known as the "thundering herd" problem, occurs in caching systems when multiple requests simultaneously expire cached data, causing all requests to trigger a resource-intensive recalculation or database query. This can lead to server overload and decreased performance.
- Python Interview Questions (Part 2)
- What is python used for?
- Is Python interpreted, or compiled, or both?
- Explain how python is interpreted
- How do I install pip on Windows?
- How do you protect Python source code?
- What are the disadvantages of the Python?
- How would you achieve web scraping in Python?
- How to Python Script executable on Unix
- What is the difference between .py and .pyc files?
- What is __init__.py used for in Python?
- What does __name__=='__main__' in Python mean?
- What is docstring in Python?
- What is the difference between runtime and compile time?
- How to use *args and **kwargs in Python
- Purpose of "/" and "//" operator in python?
- What is the purpose pass statement in python?
- Why isn't there a switch or case statement in Python?
- How does the ternary operator work in Python?
- What is the purpose of "self" in Python
- How do you debug a program in Python?
- What are literals in python?
- Is Python call-by-value or call-by-reference?
- What is the process of compilation and Loading in python?
- Global and Local Variables in Python
- Static analysis tools in Python
- What does the 'yield' keyword do in Python?
- Python Not Equal Operator (!=)
- What is the difference between 'is' and '==' in python
- What is the difference between = and == in Python?
- How are the functions help() and dir() different?
- What is the python keyword "with" used for?
- Why isn't all memory freed when CPython exits
- Difference between Mutable and Immutable in Python
- Python Split Regex: How to use re.split() function?
- Accessor and Mutator methods in Python
- How to Implement an 'enum' in Python
- What is Object in Python?
- How to determine the type of instance and inheritance in Python
- Python Inheritance
- How is Inheritance and Overriding methods are related?
- How can you create a copy of an object in Python?
- Class Attributes vs Instance Attributes in Python
- Static class variables in Python
- Difference between @staticmethod and @classmethod in Python
- How to Get a List of Class Attributes in Python
- Does Python supports interfaces like in Java or C#?
- How To Work with Unicode strings in Python
- Difference between lists and tuples in Python?
- What are differences between List and Dictionary in Python
- Different file processing modes supported by Python
- Python append to a file
- Difference Between Multithreading vs Multiprocessing in Python
- Is there any way to kill a Thread in Python?
- What is the use of lambda in Python?
- What is map, filter and reduce in python?
- Is monkey patching considered good programming practice?
- What is "typeerror: 'module' object is not callable"
- Python: TypeError: unhashable type: 'list'
- How to convert bytes to string in Python?
- What are metaclasses in Python?