Govt. Exams
Entrance Exams
The * operator in unpacking collects remaining elements. a gets [1, 2] and b gets 3.
Sets remove duplicate elements. set([1, 2, 2, 3, 3, 3]) returns {1, 2, 3}.
Lambda creates an anonymous function. f = lambda x: x2 creates a function that returns x squared. f(5) = 52 = 25.
The * operator unpacks the list. print(*[1, 2, 3]) becomes print(1, 2, 3) which prints '1 2 3' with spaces.
int('abc') raises a ValueError. The except block catches it and prints 'error' (without quotes).
any() returns True if at least one element in the iterable is True.
List comprehension: i**2 for i in [0,1,2,3] produces [0, 1, 4, 9].
dict.items() returns key-value pairs as tuples, converted to a list: [('a', 1), ('b', 2)].
int('10.5') raises TypeError because '10.5' is a string representation of a float, not a valid integer string.
The | operator performs set union, combining all unique elements from both sets. Result is {1, 2, 3, 4, 5}.