KnowledgeBoat Logo
|

Informatics Practices

Write the output for the following print statements in Python.

Sub_Teacher = {"English":"Mr. Gill", "Maths": "Mr. R.N. Pandey", "IP":"Ms. Renu Ahuja", "Physics": "Ms. Meenu Lal", "Chemistry":"Ms. Mamta Goel"}
print(Sub_Teacher['Chemistry'])  #Line1
print(Sub_Teacher.keys())       #Line2
print(len(Sub_Teacher))        #Line3

Python Dictionaries

1 Like

Answer

Ms. Mamta Goel
dict_keys(['English', 'Maths', 'IP', ' Physics', 'Chemistry'])
5

Working

  1. print(Sub_Teacher['Chemistry']) — This line retrieves the value associated with the key 'Chemistry' from the dictionary, which is "Ms. Mamta Goel".
  2. print(Sub_Teacher.keys()) — This line lists all the keys in the Sub_Teacher dictionary. The keys() method returns a list of dictionary’s keys.
  3. print(len(Sub_Teacher)) — This line calculates the number of key-value pairs in the Sub_Teacher dictionary using the len() function. It returns 5, indicating the total number of key-value pairs in the dictionary.

Answered By

3 Likes


Related Questions