ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
a, b = 1, 2 a, b = b, a + b print(a, b)
- A. 2 1
- B. 1 3
- C. 2 3
- D. 3 2
Correct answer: C. 2 3
The right-hand side (b, a+b) = (2, 1+2=3) is fully evaluated using the OLD values of a and b before any assignment happens, then unpacked: a becomes 2, b becomes 3.
More Python Programming questions
- What is printed? python from dataclasses import dataclass @dataclass class Point: x: int y: int = 0 p1 = Point(1, 2) p2 = Point(1, 2)…
- What is printed? python x, y = "hello" print(x, y)
- What is printed? python print([x for x in range(20) if x % 2 == 0 if x % 3 == 0])
- What is printed? python print([x if x % 2 == 0 else -x for x in range(5)])
- What is printed? python words = ["banana", "kiwi", "apple", "fig"] print(sorted(words, key=len)) print(sorted(words, key=lambda w: w[-1]))
- What is printed? python s = "Hello World" print(s.swapcase()) print(s.title()) print(" a b ".split())