Q1. Which of the following is true for a lambda function in Python?
- A lambda function is a small anonymous function.
- A lambda function can take any number of arguments, but can only have one expression.
- Lambda functions are used for functional programming.
- All of the above.
Q2. Which of the following is the recommended way to ensure that a file object is properly closed after usage?
- Use close() function after the use of file object.
- Use try/finally block
- Use with statement
- All of the above.
Q3. What will be the output of following code:
1 2 |
import sys print(sys.getsizeof(()), sys.getsizeof(('a', 'b')), sys.getsizeof(('a', 'b', (1, 2)))) |
- 0 2 3
- 0 16 24
- 48 64 72
- 32 96 128
Q4. Which of the following list assignment in Python will throw an exception?
- x = [1, 2, ‘python’]
- x = [1, 2, [1, 2]]
- x = [‘a’, ‘b’, ‘c’, ‘a’, ‘4.5’, int(3.4)]
- None of the above.
Q5. What will be the output of following code:
1 2 |
x = ("TheAILearner") print(type(x)) |
- <class ‘tuple’>
- <class ‘str’>
- <class ‘list’>
- <class ‘int’>
Q6. If str = “AILearner”, what will be the output of print(str == ‘AILearner’, str is “AILearner”)?
- False False
- True False
- False True
- True True
Q7. What will be the output of print(13//2)?
- 6.5
- 6
- 7
- Throws an error.
Q8. What will be the output of following code:
1 2 |
x = (1120, 'a', -1120) print(max(x)) |
- 1120
- ‘a’
- -1120
- TypeError