ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
print(repr([] or {} or 0 or ""), "a" and "b" or "c", "" and 1 or 0, not "0")- A. 0 b 0 False
- B. [] b 1 False
- C. '' b 0 False
- D. '' c 0 True
Correct answer: C. '' b 0 False
`or` returns the first truthy operand or else the LAST operand (here ''). 'a' and 'b' gives 'b', which is truthy, so the or returns it. '' and 1 gives '', so the or returns 0. '0' is a non-empty string, hence truthy, and not makes it False.
More Python Programming questions
- What is printed? python def f(a, b): return a // b if b else None vals = [(7, 2), (-7, 2), (7, 0), (7.0, -2)] print([f(p) for p in vals]…
- What is printed? python print(int("12", 8), oct(64), hex(-255), int("z", 36), format(10, "b").zfill(6))
- What is printed? python x = 2 63 print(x.bitlength(), (x - 1).bitlength(), x >> 62, (-1) >> 100, 1 << 0, (5).tobytes(2, "big"))
- What is printed? python import math print(math.floor(-2.5), math.ceil(-2.5), math.trunc(-2.5), int(-2.5), round(-2.5), -2.5 // 1)
- What is printed? python print(3 "ab" == "ab" 3, [1] 3 is [1] 3, "%" in "100%", "100%%" % (), f"{{x}}")
- What is printed? python x = 10 s = f"{x=}, {x2=}, {x:04}, {'a' if x > 5 else 'b'}" print(s)