ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(5 / 2, 5 // 2, -5 / 2, -5 // 2)
- A. 2.0 2 -2.0 -3
- B. 2.5 2 -2 -3
- C. 2.5 2 -2.5 -3
- D. 2.5 2 -2.5 -2
Correct answer: C. 2.5 2 -2.5 -3
/ always gives a float. // floors toward negative infinity, so -5 // 2 is -3, not -2 as truncation would give.
More Python Programming questions
- What is printed? python s = 'abc' print(s 0 == '', s[5:] == '', s[-1] + s[0])
- What is printed? python print(divmod(-9, 2), divmod(9, -2))
- What is printed? python x = [1, 2] x += x x = 2 print(x)
- What is printed? python d = dict(zip('abc', range(3))) print(d.popitem(), d)
- What is printed? python t = (3, 1, 2) print(sorted(t) == list(t), tuple(sorted(t)), t)
- What is printed? python print(max('apple', 'banana', key=len), max([], default=None))