Python Programming Interview Questions & Answers
1. What are the key features of Python?
- Easy-to-read and write syntax
- Interpreted language
- Dynamically typed
- Object-oriented
- Large standard library
- Cross-platform support
2. What are Python's data types?
- Numeric: int, float, complex
- Text: str
- Sequence: list, tuple, range
- Set: set, frozenset
- Mapping: dict
- Boolean: bool
- Binary: bytes, bytearray, memoryview
- Special: NoneType
3. What is the difference between list and tuple?
List:
- Mutable
- Defined using []
- Slower
Tuple:
- Immutable
- Defined using ()
- Faster
4. What is a dictionary in Python?
Python Programming Interview Questions & Answers
A dictionary is an unordered collection of key-value pairs.
Example: student = {"name": "Chaitra", "age": 22}
5. What is the difference between is and ==?
== compares values, while is compares object identity (memory location).
6. What are *args and **kwargs?
*args: variable-length positional arguments
**kwargs: variable-length keyword arguments
7. What is a lambda function?
A lambda is an anonymous function written in one line.
Example: square = lambda x: x*x
8. What is the difference between break, continue, and pass?
- break: exits loop
- continue: skips to next iteration
- pass: does nothing
9. What is a Python module and package?
- Module: single .py file
- Package: directory with modules and __init__.py
10. What is PEP 8?
PEP 8 is the official style guide for writing Python code.
11. What are decorators?
Python Programming Interview Questions & Answers
Decorators are functions that modify the behavior of other functions.
12. What is the Global Interpreter Lock (GIL)?
The GIL allows only one thread to execute at a time in Python.
13. What are list comprehensions?
A compact way to create lists.
Example: [x**2 for x in range(5)]
14. What are Python's memory management features?
- Automatic garbage collection
- Reference counting
- Memory managed in private heap
15. Difference between @staticmethod and @classmethod?
@staticmethod: no first argument
@classmethod: first argument is class (cls)