ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
s = {1, 2}
t = s
t |= {3}
print(s, s is t)- A. {1, 2} True
- B. {1, 2, 3} False
- C. {3} True
- D. {1, 2, 3} True
Correct answer: D. {1, 2, 3} True
|= on a set mutates it in place, and t is the same object as s, so both names show the new element.
More Python Programming questions
- What is printed? python print(int(3.99), int(-3.99), round(3.5), round(4.5))
- What is printed? python print('ab' in ['ab', 'cd'], 'ab' in 'cdab', [] in [[]])
- What is printed? python x = [1, 2, 3] del x[::2] print(x)
- What is printed? python print(max(map(len, ['aa', 'b', 'ccc'])))
- What is printed? python print(bool(range(0)), bool(range(1)), bool({0: 0}))
- What is printed? python print(sorted([True, 0, 2, False]))