python
x = [1, 2, 3]
y = x
y.append(4)
print(x)
What will be the output?
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].
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.
x += 3 is equivalent to x = x + 3. Starting with x=5, after adding 3, x becomes 8.
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}.
The 'in' operator checks if 'a' is a substring of 'banana'. It is present (multiple times), so it returns True.
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].
This is a ternary conditional expression. Since 5 > 3 is True, the expression evaluates to 10 (the value before 'if').
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.