ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
a = "abc" b = a a += "d" print(a, b)
- A. abcd abcd
- B. abcd abc
- C. abc abcd
- D. abc abc
Correct answer: B. abcd abc
Strings are immutable. a += "d" builds a NEW string and rebinds a to it. b still points to the original "abc". Compare this with lists, where += changes the list in place.
More Python Programming questions
- What is printed? python t = (1, [2, 3]) t[1].append(4) print(t)
- What is printed? python print(0.1 + 0.2 == 0.3, abs(0.1 + 0.2 - 0.3) < 1e-9)
- What is printed? python def outer(): n = 0 def inc(): nonlocal n n += 1 return n return inc c = outer() c(); c() print(c())
- What is printed? python print([1, 2, 3], sep="-", end="!n")
- What is printed? python print("%d items" % 3.9, int("0x1A", 16))
- What is printed? python def f(a, b=2, c, d=4): return a + b + sum(c) + d print(f(1, 3, 5, 7, d=1))