ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(bool('0'), bool(0.0), bool(-0.0), bool(float('nan')), bool(' '))- A. True False True True False
- B. False False False True True
- C. True False False True True
- D. True True False True True
Correct answer: C. True False False True True
Any non-empty string is True, including '0' and a single space. Zero floats, including -0.0, are False, but NaN is non-zero and therefore True.
More Python Programming questions
- What is printed? python print(True & 2, True | 2, True ^ True, ~True)
- What is printed? python print(-263 // -1 == 263, abs(-263) == 263, (263) (263) > 2127, 263 263 == 2126)
- What is printed? python print(int(1e22) == 1022, int(1e23) == 1023, float(1022) == 1e22)
- What is printed? python print('{:+}'.format(-0.0), '{:+}'.format(0), '{:+.1f}'.format(-0.04), '{:+}'.format(5))
- What is printed? python print(hex(255).upper(), int('FF', 16) == 0xff, '%X' % 255 == hex(255)[2:].upper(), oct(64))
- What is printed? python print(0.1 + 0.2 != 0.3, 1 if 0.1 + 0.2 else 0, 0.0 or -0.0 or 'x', 0 and 1 or 2)