ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(1 if 0 else 2 if 3 else 4, 0 or '' or 'z', 0 and 'z')
- A. 2 0 0
- B. 4 z 0
- C. 2 z False
- D. 2 z 0
Correct answer: D. 2 z 0
The conditional chain picks 2 because 0 is falsy and 3 is truthy. 'or' returns the first true operand, 'z'. 'and' stops at the first falsy operand, 0.
More Python Programming questions
- What is printed? python a = [1, 2, 3] b = a 2 b[0] = 9 print(a, b)
- What is printed? python s = 'xxxy' print(s.rstrip('y'), s.strip('x'), repr(s.lstrip('xy')))
- What is printed? python print('abc' < 'abcd', 'Z' < 'a', '10' < '9')
- What is printed? python i = 0 while (i := i + 1) < 4: pass print(i)
- What is printed? python print(float('nan') < 0, float('inf') > 10 300, -float('inf') < -10 300)
- What is printed? python print(10 309 > float('inf'), end=' ') try: float(10 309) except OverflowError as e: print(e)