ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(type(1 / 2).__name__, type(1 // 2).__name__, type(2 ** -1).__name__, type(2 ** 0.5).__name__, type(True + 1).__name__)
- A. float int float float int
- B. int int float float int
- C. float int int float int
- D. float int float int int
Correct answer: A. float int float float int
/ always gives a float and // on ints gives an int. A negative int exponent gives a float, a fractional exponent gives a float, and bool plus int is an int.
More Python Programming questions
- What is printed? python print(sorted(['10', '9', '1.5']), sorted(['10', '9', '1.5'], key=float))
- What is printed? python print(max('the', 'a', key=len), min(['b', 'B'], key=str.lower), ''.join(sorted('cab')), 'cab'.upper().swapcase())
- What is printed? python print(int(str(1020 + 1)[-1]) + len(str(1020)), 1020 + 1 == int(str(1020 + 1)))
- What is printed? python print(divmod(7.5, 2), divmod(-7.5, 2), 7.5 % -2, -7.5 // -2)
- What is printed? python print(-7 % 4, -7 % -4, 7 % -4, (-7) % 4 == -7 % 4)
- What is printed? python def edit(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(len(a) + 1): for j in range(len(b)…