ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
import operator print(operator.index(5), operator.mod(-7, 3), operator.floordiv(-7, 3))
- A. 5 -1 -2
- B. 5 2 -2
- C. 5 1 -3
- D. 5 2 -3
Correct answer: D. 5 2 -3
operator.index returns the int itself. Python's % gives a result with the divisor's sign, so -7 mod 3 is 2, and floor division of -7 by 3 is -3.
More Python Programming questions
- What is printed? python print(sorted(['b', 'B', 'a', 'A'], key=lambda s: s.swapcase()))
- What is printed? python print(len(set('mississippi')), sorted(set('mississippi')))
- What is printed? python print(7 -1 == 1 / 7, pow(7, -1, 13) 7 % 13, (7 2) % 13, 2 3 2 % 10)
- What is printed? python x = [0] 3 x[0] += 1 y = [[0]] 2 y[0][0] += 1 print(x, y)
- What is printed? python print(int(float('1e16')) + 1, float(int(260) + 1) == float(260))
- What is printed? python print('a-bc d'.split('-'), 'a-bc d'.replace('-', ' ').split(''), 'a-b'.partition('-')[0])