ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(3 * [0] == [0, 0, 0], [0] * 3 is [0] * 3, 'a' in 'abc' in 'abcdef')
- A. False False True
- B. True True False
- C. True False True
- D. True True True
Correct answer: C. True False True
Two separate list multiplications create different objects, so the is test is False. The chained in checks 'a' in 'abc' and 'abc' in 'abcdef', both True.
More Python Programming questions
- What is printed? python print(sum([1, 2, 3]) / 2 // 1, 7 // 2 / 2, divmod(7.0, 2)[0] == 7 // 2)
- What is printed? python print('{:^6}'.format('ab'), '{:<4}'.format(1), '{:>3}|{:<3}|'.format('a', 'b'))
- What is printed? python print('a' < 'b' < 'c', 'b' > 'a' and 'b' > 'c')
- What is printed? python print(len([range(3), 'ab']), ['ab', [1]], {{'a': 1}, 'a': 2})
- What is printed? python print(hash(()) == hash(()), (1, 2) < (1, 2, 0), 'b' 2 > 'ab' 2, (1, 'b') < (1, 'a'))
- What is printed? python print(sorted(['b', 'B', 'a'], key=lambda s: (s.lower(), s)))