ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
t = (1, [2])
t[1].append(3)
print(t, len(t))
try:
t[0] = 5
except TypeError as e:
print(type(e).__name__)- A. (1, [2, 3]) 2 then ValueError
- B. (1, [2]) 2 then TypeError
- C. (1, [2, 3]) 3 then TypeError
- D. (1, [2, 3]) 2 then TypeError
Correct answer: D. (1, [2, 3]) 2 then TypeError
A tuple itself is immutable, so item assignment raises TypeError, but the list inside it can still be changed. The tuple's contents therefore show [2, 3] after the append.
More Python Programming questions
- What is printed? python print(bin(0b1010 << 2 >> 1 & 0xF), 0o17 + 0x1F + 0b11, 0xff, 10j)
- What is printed? python x = 0 x |= 1 << 3 x &= ~(1 << 0) x ^= 0b111 print(x, x.bitcount(), (x >> 1) & -x)
- What is printed? python print(-(-231) // 1, (231 - 1) & -(231), 231 >> 31, 232 & -232)
- What is printed? python print((1 << 3) - 1 << 2, 1 << 3 - 1 << 2, 1 + 2 << 1, 3 & 2 2)
- What is printed? python print(0 0, 0.0 0, (-8) 0, (-2) 3, -2 3)
- What is printed on the first line? python print(sorted(['10', '9', '2'], key=int)) print(sorted(['10', '9', '2'])) print(sorted(['a', 'B'…