Govt. Exams
Entrance Exams
None and False are distinct objects. None == False evaluates to False. None is a unique singleton object, not equivalent to False or 0.
Tuples are immutable. Attempting to modify a tuple element with x[0] = 5 raises a TypeError: 'tuple' object does not support item assignment.
Dictionaries are mutable. The assignment d['c'] = 3 adds a new key-value pair to the dictionary. d becomes {'a': 1, 'b': 2, 'c': 3}.
List slicing x[1:4] includes indices 1, 2, 3 (but excludes 4). Elements are 2, 3, 4 from the list [1, 2, 3, 4, 5].
y has a default value of 5. When func(3) is called, x=3 and y=5 (default). The function returns 3 + 5 = 8.
Due to string interning in Python, small strings may be cached and refer to the same object. However, this is an implementation detail. a == b is True, but a is b may vary.
Exponentiation is right-associative. 3 2 2 = 3 (2 2) = 3 ** 4 = 81.
y = x creates a reference to the same list object. When y.append(4) is called, it modifies the original list. Both x and y point to [1, 2, 3, 4].
String multiplication repeats the string. 'abc' * 3 produces 'abcabcabc' and print displays it without quotes.
lst[1] refers to the nested list [2, 3]. lst[1][0] refers to the first element of that nested list, which is 2.