Adding an item to the dictionary

Adding an item to the dictionary is very simple; just specify a new key in the square brackets along with the dictionary. The syntax is as follows:

dict[new_key] = value 

Consider the following example:

>>> port = {80: "HTTP", 23 : "Telnet"}
>>> port[110]="POP"
>>> port
{80: 'HTTP', 110: 'POP', 23: 'Telnet'}
>>>

In the preceding example, we added the "POP" protocol.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.114.85