ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print('abc' < 'abd' and 'x' or 'y', [] or 'empty', 0 or 0.0 or 'z')- A. y empty z
- B. x empty z
- C. x [] z
- D. x empty 0
Correct answer: B. x empty z
'abc' < 'abd' is True, so and returns 'x', which is truthy, so or does not evaluate 'y'. An empty list is falsy, so the or returns 'empty', and 0 or 0.0 or 'z' returns z.
More Python Programming questions
- What is printed? python print(len({'a': 1, 'a': 2}), {'a': 1, 'a': 2}, list({1, 2, 1}), sorted({3, 1, 2} & {2, 3, 4}))
- What is printed? python print('Ab'.swapcase(), 'ab'.capitalize() == 'Ab', 'AB'.lower() == 'ab', 'a b'.title())
- What is printed? python print(3 > 2 > 1, 3 > 2 and 2 > 1, (3 > 2) + (2 > 1))
- What is printed? python print(sorted([0.5, 1, True, False]), max(0.5, 1, True))
- What is printed? python print('%s|%s' % ('a', 'b'), 'ok', '%5.1f%%' % 99.55)
- What is printed? python print(len(set('aabbcc')), sorted(set('cba')), 'abc'.index('b') + 'abc'.count('b'))