ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
x = [1, 2, 3] y = x x = x + [4] print(y, x, y is x)
- A. [1, 2, 3] [1, 2, 3, 4] False
- B. [1, 2, 3, 4] [1, 2, 3, 4] False
- C. [1, 2, 3] [1, 2, 3, 4] True
- D. [1, 2, 3, 4] [1, 2, 3, 4] True
Correct answer: A. [1, 2, 3] [1, 2, 3, 4] False
+ builds a new list, so x is rebound to that new list. y still refers to the original, which keeps three items, and the two names no longer share an object.
More Python Programming questions
- What is printed? python print(int('٤٢'), '٤٢'.isnumeric(), ' 42n'.isdigit(), int('42n'))
- What is printed? python from collections import Counter c = Counter() c['a'] += 2 c.update('ab') print(c['a'], c['b'], c['z']…
- What is printed? python print(pow(2, 1018, 109 + 7) == pow(2, 1018 % (109 + 6), 109 + 7))
- What is printed? python print(7 // 0.5, 7 % 0.5, 0.5 7 // 1, 1e308 10 == float('inf'))
- What is printed? python print(sum([True, True, False]), True 3, 'ab' True, [0] True)
- What is printed? python print('%x' % 255, '%X' % 255, '%#o' % 8, '%+d' % 0)