Consider: a = 'Hello'; b = 'Hello'. Are a and b the same object?
Answer: C
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.
Q.91Medium
Consider the code: def func(x, y=5): return x + y. What is func(3)?
Answer: C
y has a default value of 5. When func(3) is called, x=3 and y=5 (default). The function returns 3 + 5 = 8.
Q.92Easy
What will be the output of: print(10 if 5 > 3 else 20)?
Answer: A
This is a ternary conditional expression. Since 5 > 3 is True, the expression evaluates to 10 (the value before 'if').
Q.93Medium
Consider: x = [1, 2, 3, 4, 5]; y = x[1:4]. What is y?
Answer: B
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].
Q.94Easy
What is the output of: print('a' in 'banana')?
Answer: A
The 'in' operator checks if 'a' is a substring of 'banana'. It is present (multiple times), so it returns True.
Q.95Medium
Consider: d = {'a': 1, 'b': 2}; d['c'] = 3. What is d?
Answer: B
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}.
Q.96Easy
What will be the output of: x = 5; x += 3; print(x)?
Answer: C
x += 3 is equivalent to x = x + 3. Starting with x=5, after adding 3, x becomes 8.
Q.97Medium
Consider the code: x = (1, 2, 3); x[0] = 5. What happens?
Answer: B
Tuples are immutable. Attempting to modify a tuple element with x[0] = 5 raises a TypeError: 'tuple' object does not support item assignment.
Q.98Medium
What is the output of: print(None == False)?
Answer: B
None and False are distinct objects. None == False evaluates to False. None is a unique singleton object, not equivalent to False or 0.
Q.99Medium
Consider the following code snippet:
python
x = [1, 2, 3]
y = x
y.append(4)
print(x)
What will be the output?
Answer: A
In Python, when you assign y = x, both variables reference the same list object in memory. When you modify the list using y.append(4), the original list x is also modified because they point to the same object. Therefore, print(x) outputs [1, 2, 3, 4].