ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
t = ([],) t[0].append(1) print(t, t[0] is t[0])
- A. ([1],) True
- B. ([],) True
- C. ([1],) False
- D. ([1],) None
Correct answer: A. ([1],) True
A tuple cannot change its own items, but the list inside it can be mutated. t[0] is the same list object each time.
More Python Programming questions
- What is printed? python print(list(dict.fromkeys('mississippi')))
- What is printed? python print(any([]) or all([]) and 'x')
- What is printed? python s = 'hello' print(s[1:-1][::-1], s[-1:0:-2])
- What is printed? python d = {} d.setdefault('k', []).append(1) d.setdefault('k', []).append(2) print(d)
- What is printed? python print(1 / 3 + 1 / 3 + 1 / 3 == 1.0, 0.1 + 0.7)
- What is printed? python print(sorted([(-1, 'b'), (-1, 'a'), (0, 'c')]), max([(1, 'z'), (1, 'a')]))