Updating the values of the dictionary

Updating the dictionary is pretty simple; just specify the key in the square bracket along with the dictionary name. The syntax is as follows:

dict[key] = new_value 

Consider the following example:

port = {80: "HTTP", 23 : "SMTP”, 443 : "HTTPS"} 

In the preceding dictionary, the value of port 23 is "SMTP", but in reality, port number 23 is for telnet protocol. Let's update the preceding dictionary with the following code:

>>> port = {80: "HTTP", 23 : "SMTP", 443 : "HTTPS"}
>>> port
{80: 'HTTP', 443: 'HTTPS', 23: 'SMTP'}
>>> port[23] = "Telnet"
>>> port
{80: 'HTTP', 443: 'HTTPS', 23: 'Telnet'}
>>>
..................Content has been hidden....................

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