ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(sorted([1.0, True, 1, 0.5, False]))
- A. [False, 0.5, 1.0, True, 1]
- B. [False, 0.5, True, 1, 1.0]
- C. [False, 0.5, 1, 1.0, True]
- D. [False, 0.5, 1.0, 1, True]
Correct answer: A. [False, 0.5, 1.0, True, 1]
True, 1 and 1.0 compare equal, so sorted keeps their input order: 1.0, then True, then 1. The 0.5 sits between 0 and 1, and False is the smallest value.
More Python Programming questions
- What is printed? python try: print(int('10')) except ValueError: print('bad')
- What is printed? python print(float('1e400'), -float('1e400'), float('1e308') 10)
- What is printed? python print(int(1e23))
- What is printed? python print('x' 0 == '', 'Z' < 'a', '10' < '9', 'apple' < 'Apple')
- What is printed? python print(len('eu0301'), 'é' == 'eu0301')
- What is printed? python print(0b1010 & ~0b10, 0b1010 ^ 0b1111, 1 << 3 | 1, 6 & 3 == 2)