1.
Python Basics & Syntax
Q: What is the difference between is and == in Python?
A: `is` checks for object identity, i.e., whether two variables point to the same object. `==` checks for
value equality.
Q: How is Python an interpreted language? What does that mean?
A: Python code is executed line by line by an interpreter, rather than being compiled into machine
code.
Q: What are Pythons data types? How do mutable and immutable types differ?
A: Python has types like int, float, str, list, tuple, dict, set. Mutable types (e.g., list, dict) can be
changed; immutable types (e.g., int, str, tuple) cannot.
Q: What is the purpose of the with statement in Python?
A: It simplifies exception handling by automatically managing resources (e.g., files) using context
managers.
Q: Explain how Python handles memory management.
A: Python uses reference counting and a cyclic garbage collector to manage memory automatically.
2. Control Flow & Functions
Q: What is the difference between break, continue, and pass?
A: `break` exits a loop, `continue` skips to the next iteration, `pass` does nothing (a placeholder).
Q: Explain *args and **kwargs in Python with an example.
A: `*args` collects extra positional arguments, `**kwargs` collects extra keyword arguments.
Example:
```python
def func(*args, **kwargs):
print(args, kwargs)
```
Q: How do default arguments work in Python functions?
A: They are assigned if no value is provided by the caller.
Example:
```python
def greet(name="World"): print(f"Hello {name}")
```
Q: Write a function to find factorial using recursion.
A: ```python
def factorial(n):
return 1 if n == 0 else n * factorial(n-1)
```
Q: What is a lambda function? When would you use it?
A: An anonymous, single-expression function. Used for short, throwaway functions.
Example: `square = lambda x: x*x`