Govt. Exams
Entrance Exams
The 'in' operator checks for key existence in a dictionary. has_key() was removed in Python 3.
Negative indexing starts from the end. s[-1] gives the last character 'n'. s = 'Python' has characters indexed from 0 to 5.
Python tuple unpacking allows simultaneous assignment, effectively swapping x and y.
String slicing s[2:5] includes indices 2, 3, 4. 'Python'[2:5] = 'tho'.
range(3) generates 0, 1, 2. The end=' ' parameter prevents newline after each print.
The // operator performs floor division, returning the integer quotient.
0, empty string '', and empty list [] are all falsy values in Python, so bool() returns False for each.
y = x creates a reference to the same list, not a copy. Modifying y also modifies x.
extend() adds each element of the iterable to the list, resulting in [1, 2, 3, 4, 5].
int('25') converts the string to integer 25, then 25 + 5 = 30.