ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
s = 'abc' t = s s += 'd' print(t, s, t is s, id(s) == id(t))
- A. abc abcd False False
- B. abcd abcd False False
- C. abc abcd True True
- D. abc abc False False
Correct answer: A. abc abcd False False
Strings are immutable, so += creates a new object and rebinds s. t still refers to the old string 'abc', so the two names no longer point to the same object.
More Python Programming questions
- What is printed? python def tosigned(v): return v - (1 << 32) if v >= 1 << 31 else v print(tosigned(0xFFFFFFFE), tosigned(0x7FFFFFFF)…
- What is printed? python s = 'hello world' print(s.capitalize(), s.title().swapcase(), s.center(15, ''), s.zfill(13))
- What is printed? python print(divmod(-7, 2), divmod(7, -2.0), 7 // -2.0, -7 % 2.5)
- What is printed? python x = -17 print(x // 5, x % 5, divmod(x, -5), x.mod(5))
- What is printed? python print(1018 + 1 == 1000000000000000001, 231 - 1 + 1, -(231), (231) (231) == 262)
- What is printed? python s = 'a' for i in range(3): s = s + s[::-1] + str(i) print(s, len(s))