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
print(Sub_Teacher['Chemistry'])
— This line retrieves the value associated with the key 'Chemistry' from the dictionary, which is "Ms. Mamta Goel".print(Sub_Teacher.keys())
— This line lists all the keys in theSub_Teacher
dictionary. Thekeys()
method returns a list of dictionary’s keys.print(len(Sub_Teacher))
— This line calculates the number of key-value pairs in theSub_Teacher
dictionary using thelen()
function. It returns 5, indicating the total number of key-value pairs in the dictionary.
Answered By
3 Likes
Related Questions
Five friends plan to start a new business. However, they have a limited budget and limited computer infrastructure. Which benefits of cloud services they can avail to launch their startup?
What is a server?
Rohit, a Librarian has created a Table Book with the following fields:
Bookid, Bookname, Author and Price. He has entered 20 records in the table.
Which command should he use to do the following:
(i) To change the price of Computer Science book from 450 to 500.
(ii) To insert Primary Key in the table.
(iii) What is the difference between delete and drop command.
The data type list is an ordered sequence which is mutable and made up of one or more elements. Unlike a string which consists of only characters, a list can have elements of different data types such as integer, float, string, tuple or even another list. A list is very useful to group elements of mixed data types. Elements of a list are enclosed in square brackets and are separated by comma.
(i) How is a list different from a dictionary?
(ii) Find the values of y and z after execution:
x=[2, 3] y=[30, 40] z=[88, 99] y.extend(x) z.append(x) print (y) print (z)