ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(True + True, 3 * True, 'ab' * True)
- A. 2 3 abab
- B. 2 3 ab
- C. 2 True ab
- D. 1 3 ab
Correct answer: B. 2 3 ab
bool is an int subclass, so True acts as 1 in arithmetic and in repetition. 'ab' * True is 'ab'.
More Python Programming questions
- What is printed? python print('%.3e' % 12345.678)
- What is printed? python print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1])
- What is printed? python print([0] 3 == [0, 0, 0], [[]] 2 == [[], []])
- What is printed? python print(len([x for x in range(100) if x % 7 == 0]), sum(range(0, 100, 7)))
- What is printed? python print(round(-2.5), round(-3.5), round(-2.5 - 1e-9))
- What is printed? python print(7 -1 7, (7 -1) 7 == 1.0)