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())
  1. A. 1 2 False True
  2. B. 1 2 True True
  3. C. 0 2 True True
  4. 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

Exams that ask this topic