### Advanced Python Questions
11. What is the output of the following code?
```python
def foo(x=[]):
x.append(1)
return x
print(foo())
print(foo())
```
- A) [1], [1]
- B) [1], [1, 1]
- C) [1], []
- D) [1, 1], [1, 1]
- Answer: B) [1], [1, 1]
12. Which keyword is used to de ne a generator in Python?
- A) yield
- B) generate
- C) return
- D) generator
- Answer: A) yield
13. What is the output of the following code?
```python
print(bool('False'))
```
- A) True
- B) False
- C) 'False'
- D) Error
- Answer: A) True
14. Which of the following functions is used to get the length of a dictionary?
- A) len()
- B) count()
- C) size()
- D) length()
- Answer: A) len()
15. What is the output of the following code?
```python
a = [1, 2, 3]
b=a
a.append(4)
print(b)
```
- A) [1, 2, 3]
- B) [1, 2, 3, 4]
- C) [4]
- D) Error
- Answer: B) [1, 2, 3, 4]
### Expert Python Questions
16. Which of the following is true about Python decorators?
- A) They are used to modify the behavior of a function or class
- B) They are de ned using the `def` keyword
- C) They are called before de ning a function
fi
fi
fi
- D) They cannot be nested
- Answer: A) They are used to modify the behavior of a function or class
17. What will be the output of the following code?
```python
a = {1, 2, 3}
b = {3, 4, 5}
print(a & b)
```
- A) {1, 2, 3, 4, 5}
- B) {1, 2}
- C) {3}
- D) {1, 2, 3}
- Answer: C) {3}
18. What does the `__init__` method do in a class?
- A) It initializes the class attributes
- B) It is called automatically when an instance is created
- C) It is a constructor method
- D) All of the above
- Answer: D) All of the above
19. What will be the output of the following code?
```python
def foo():
try:
return 1
nally:
return 2
print(foo())
```
- A) 1
- B) 2
- C) Error
- D) None
- Answer: B) 2
20. Which of the following is used to handle exceptions in Python?
- A) try/except
- B) try/catch
- C) handle/except
- D) catch/handle
- Answer: A) try/except
These questions cover various aspects of Python and are designed to test fundamental as well as
advanced understanding of the language.
fi