1.

Output of : a={1:"A",2:"B",3:"C"} print(a.get(1,4))

Answer»

uired Answer:-

Given Co‎de:

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.



Discussion

No Comment Found