Computer Science

What will be the output?

D1 = { "Rahul":56, "Virat":99} 
print("virat" in D1)
  1. True
  2. False
  3. No output
  4. Error

Python Dictionaries

1 Like

Answer

False

Reason — In Python, dictionary keys are case-sensitive. The dictionary D1 has the key "Virat" with an uppercase 'V', but the check is for "virat" with a lowercase 'v'. Since "virat" does not match the case of the key "Virat", the expression "virat" in D1 evaluates to False.

Answered By

1 Like


Related Questions