ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(3 in {1, 2, 3} and 'x' in 'xyz', [] or () or None)- A. True [0]
- B. False None
- C. True None
- D. True ()
Correct answer: C. True None
The membership tests are both True, so the and expression is True. Every operand in the or chain is falsy, so or returns the last one, None.
More Python Programming questions
- What is printed? python def flat(x): for i in x: if isinstance(i, list): yield from flat(i) else: yield i print(list(flat([1, [2, [3, 4]]…
- What is printed? python print('42'.zfill(5), '-42'.zfill(5), 'ab'.center(6, ''), 'x'.ljust(3, '.') + '|')
- What is printed? python print(10 / 2, 10 // 2, 7 / 7, 2 3 + 4)
- What is printed? python print('abc'.index('c'), 'abcabc'.rfind('b'), 'abc'.find('d'), len('abc'[1:]))
- What is printed? python print(sorted('bca'), ''.join(sorted('bca', reverse=True)), sorted([3, 1, 2], reverse=True)[0], list(reversed('ab')))
- What is printed? python print(int('12') + int('3'), '12' + '3', 12 + 3 == int('15'), 'x')