Learning knows no bounds, we will never stop
Basic format of a dictionary:
(d is the name of the dictionary)
d = {
"key1": "value1",
'key2 (number)': 123
}
I am a separator~
Ways to add dictionary values:
d["I am a new key"] = "I am a new value"
or:
d.setdefault("I am a new key","I am a new value")
Ways to delete key-value pairs:
del d["I am a new key"]
#Delete a single key-value pair
or:
d.popitem()
#Delete a random key-value pair
I am a separator~
dict.items()
↑Used when iterating over a dictionary, feels like magic
Example:
key = {
"nima" : "Python",
"niniang" : "Java" ,
"ni" : "C#"
}
for key1,values in key.items():
print(key1,values)
Output:
nima Python
niniang Java
ni C#
I am a separator~