161. What is the output of print(type(lambda x: x))?
- a) <class 'function'>
- b) <class 'lambda'>
- c) <class 'expression'>
- d) Error
Test your knowledge of Python with these interactive multiple-choice questions.
161. What is the output of print(type(lambda x: x))?
162. Which keyword is used to define a function?
def function_name():.
163. What does print((lambda x: x*2)(5)) output?
164. Which statement immediately exits a function?
return exits the function and optionally returns a value.
165. What is the output of def f(x=[]): x.append(1); return x; print(f() + f())?
166. Which symbol is used for unpacking argument lists?
* unpacks iterables, ** unpacks dictionaries.
167. What is the output of print([x for x in range(3)])?
168. Which decorator converts a method to a static method?
@staticmethod doesn't receive implicit first argument.
169. What does print(list(map(lambda x: x**2, [1,2,3]))) output?
map() applies the lambda to square each number.
170. Which function applies a function to pairs of elements?
reduce() cumulatively applies a function (from functools in Python 3).
171. What is the output of print([x for x in range(5) if x%2==0])?
172. Which decorator converts a method to a class method?
@classmethod receives the class as first argument.
173. What is the output of print(list(filter(lambda x: x>0, [-1,0,1,2])))?
filter() keeps only elements where lambda returns True.
174. Which function creates an iterator of tuples from multiple iterables?
zip([1,2], ['a','b']) yields (1,'a'), (2,'b').
175. What does print({x:x**2 for x in range(3)}) output?
176. Which function adds a counter to an iterable?
enumerate(['a']) yields (0,'a').
177. What is the output of print((x**2 for x in range(3)))?
178. Which function returns a list of results from applying a function?
map() applies a function to each item in an iterable.
179. What does print(sorted([3,1,2], reverse=True)) output?
reverse=True sorts in descending order.
180. Which function returns a list of elements where function returns True?
filter() includes only elements that satisfy the condition.