output of :
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
Answers
Answered by
2
Required Answer:-
Given Code:
a={
1:"A",
2:"B",
3:"C"
}
print(a.get(1,4))
Output:
>> A
Explanation:
- The get() method returns the value of the item with specified key.
- Syntax: dictionary.get(keyname,value).
- Here, keyname is 1 and the value is 4.
- So, the get() method returns the value in the dictionary whose key us 1 i.e., it returns the value - "A".
- The second parameter is an optional parameter. If the keyname is not in the dictionary, the get() method returns the value written in the second parameter.
- As we can see that the keyname '1' is present in the dictionary, the get() returned "A" which is displayed on the screen.
See the attachment for output.
Attachments:
Similar questions
Social Sciences,
1 month ago
Physics,
1 month ago
Math,
3 months ago
Social Sciences,
3 months ago
Math,
10 months ago
Hindi,
10 months ago
English,
10 months ago