ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(float(' 1_000.5 '), float('infinity') > 1e308, float('-nan') != float('-nan'), int(' +0012 '))- A. 1000.5 True False 12
- B. 1 000.5 True True 12
- C. 1000.5 False True 12
- D. 1000.5 True True 12
Correct answer: D. 1000.5 True True 12
float() accepts underscores between digits and ignores surrounding whitespace. Infinity is larger than any finite float, and NaN is never equal to itself, including a NaN with a minus sign. int() also strips whitespace and accepts an explicit plus sign.
More Python Programming questions
- What is printed? python print(b'abc'[0], bytes([65, 66]), bytes.fromhex('41 42'), len(b'a' 2 + b'x00'))
- What is printed? python print(sorted(['b', 'A', 'c', 'B'], key=str.casefold, reverse=True))
- What is printed? python try: print(sorted([3, None, 1])) except TypeError: print('cannot compare')
- What is printed? python print('%(a)s-%(b)05.1f' % {'a': 'x', 'b': 3.14159})
- What is printed? python s = 'Ünïcödé' print(len(s), len(s.encode()), s.upper() == 'ÜNÏCÖDÉ')
- What is printed? python print(int('10', 2), int('0o17', 0), int('17', 8), int('0xff', 16))