May 2017
Intermediate to advanced
280 pages
6h 2m
English
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'}>>>
Read now
Unlock full access