ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
def k(a, b=(1, 2)):
return b
print(k(1) is k(2))- A. False
- B. True
- C. TypeError
- D. None
Correct answer: B. True
Tuples are immutable, so there is no mutation trap here, but the default value (1, 2) is still built once when the function is defined and the SAME tuple object is returned every time b is omitted, so k(1) is k(2) is True.
More Python Programming questions
- What is printed? python class Box: def init(self, items=[]): self.items = items b1 = Box() b2 = Box() b1.items.append(1) print(b2.items)
- What is printed? python print({x: x 2 for x in range(-2, 3)})
- What is printed? python data = [1, 2, 2, 3, 3, 3] print({x for x in data if x > 1})
- What is printed? python print([[y for y in range(x)] for x in range(4)])
- What is printed? python print(list(x for x in range(5) if x % 2 == 0)[1:3])
- What is printed? python print({k: v for k, v in zip(['a', 'b', 'a'], [1, 2, 3])})