ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
s = 'abc' t = s s += 'd' print(s, t, s is t)
- A. abcd abc False
- B. abcd abcd True
- C. abc abc False
- D. abcd abc True
Correct answer: A. abcd abc False
Strings are immutable, so += creates a new object and rebinds s. The name t still refers to the original 'abc' object, so the two names no longer point to the same object.
More Python Programming questions
- What is printed? python a = [1, 2] b = a 2 b[0] = 9 c = a + a c[2] = 7 print(a, b, c)
- What is printed on the first line? python grid = [[0] 2] 2 grid[0][0] = 1 print(grid) g2 = [[0] 2 for in range(2)] g2[0][0] = 1 print(g2)
- What is printed? python t = (1, [2]) t[1].append(3) print(t, len(t)) try: t[0] = 5 except TypeError as e: print(type(e).name)
- 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)