Informatics Practices
Select the correct option to get the values of marks key:
Student={ "name" : "Emma", "class" :11, "sec": "a", "marks" :76}
- Student.get(3)
- Student.get("marks")
- Student["marks"]
- Both 2 and 3
Python Dictionaries
3 Likes
Answer
Both 2 and 3
Reason — Student.get("marks") and Student["marks"] both access the value associated with the key "marks" in the Student dictionary. While Student.get(3) would return "None" because there is no key 3 in the dictionary.
Answered By
3 Likes
Related Questions
What will be the output of the following Python code snippet?
d1 = { "amit" :40, "jatin" :45} d2 = { "amit" :466, "jatin" :45} d1 > d2- True
- False
- Error
- None
Which of the following functions will return key-value pairs of the dictionary in the form of list of tuples?
- key()
- values()
- items()
- get()
Consider the given code:
D1={1: 'India', 2: 'Russia', 3: 'World'} D2={'School' : 'EOIS' , 'Place ' : 'Moscow'} print(D1.update (D2) )What will be the output of the above code:
- None
- {1: 'India' , 2: 'Russia' , 3: 'World' , 'School' : 'EOIS' , 'Place' : 'Moscow'}
- Error
- None of these
Assertion (A): Dictionary is a collection of key-value pairs.
Reasoning (R): Each key in a dictionary maps to a corresponding value. Keys are unique and act as the index.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.