ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
data = {'a': 1}
print(data.get('b', 0) + 1, data.get('a') + 1, 'a' in data, 1 in data.values())- A. 1 2 False True
- B. 1 2 True True
- C. 0 2 True True
- D. 1 3 True True
Correct answer: B. 1 2 True True
get returns the default 0 for a missing key, so the first value is 1. The key a is present with value 1, so the second value is 2, and both membership tests are True.
More Python Programming questions
- What is printed? python print(3 in range(5), 5 in range(5), range(0, 6, 2) == range(0, 7, 2), list(range(3, 0, -1)))
- What is printed? python print(10 % 4 == 2, -10 % 4 == 2, 10 // -4, 10 / -4)
- What is printed? python s = 'abcdef' print(s[-2:], s[:-2], s[-10:], s[::-2][0])
- What is printed? python print('abc' < 'abd' and 'x' or 'y', [] or 'empty', 0 or 0.0 or 'z')
- 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())