ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(str(-0), int('-0'), -0.0 == 0, str(-0.0), 0 * -1.0)- A. 1 0 True -0.0 -0.0
- B. 0 0 True -0.0 -0.0
- C. 0 0 False -0.0 -0.0
- D. 0 0 True 0.0 1.0
Correct answer: B. 0 0 True -0.0 -0.0
Integers have no negative zero, so str(-0) and int('-0') are both 0. Floats keep the sign bit, so -0.0 == 0 is True, while str(-0.0) and 0 * -1.0 both show -0.0.
More Python Programming questions
- What is printed? python print(str(1e21), str(1e15), str(123456789.123), 1e21 == 1021, float(1021) == 1e21)
- What is printed? python print(str(1e-5), 0.0001, 0.00001, 1e-4 == 0.0001, 10 -4)
- What is printed? python print(sorted(['10', '9', '2b', '2a']), sorted([10, 9, 2], key=str))
- What is printed on the last line? python try: sorted([1, '2']) except TypeError: print('TypeError') print(sorted([1, '2'], key=str))
- What is printed? python print(max([], default=-1), min([3], default=0), sum([]), sum([], 0.0), any([]) or all([]))
- What is printed on the first line? python words = ['apple', 'Bob', 'cat', 'Dog', 'ant'] print(sorted(words, key=lambda w: (w[0].lower()…