ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(7 / 7, 0 / 5, -0 / 5, 2 ** 0, 0 ** 0.0)
- A. 1 0.0 0.0 1 1.0
- B. 1.0 0.0 0.0 2 1.0
- C. 1.0 0.0 0.0 1 1.0
- D. 1.0 0.0 0.0 1 0.0
Correct answer: C. 1.0 0.0 0.0 1 1.0
/ always returns a float, while ** with int operands stays an int when the exponent is a non-negative int. -0 is just the integer 0, and 0 ** 0.0 is 1.0 because the float exponent makes the result a float.
More Python Programming questions
- What is printed? python print(7 // 1.0 1, 1e3 // 7, -1e3 // 7, 10 % -3.0)
- What is printed? python print(bool(''), bool('False'), bool([]), bool([[]]), bool(None))
- What is printed? python print(str(3) + str(3.0), 3 + 3.0, '3' 3 == '333')
- What is printed? python y = 1 + 1 - 1 2 2 // 4 print(y, 2 2 0, (2 2) 0, -3 2 % 5)
- What is printed? python t = 'racecar' print(t == t[::-1], t.find('car'), t.rfind('c'), t.replace('car', 'CAR', 1))
- What is printed? python s = 'one two three' print(s.split(' '), len(s.split()), s.split(None, 1)[1], '-'.join(s.split()))