|
A dictionary is changeable and indexed like a list and unordred like a set. A dictionairy contains keys and values.
|
Car = { |
thisdict = dict(brand="Ford", model="Focus", year=2013) |
|
Example 1
x = Car["model"] Example 2 x = Car.get("model") |
Car["year"] = 2019 |
|
Check if "year" is present in the dictionary:
if "year" in Car: |
print(len(Car)) |
Car["Combined MPG"] = 32 |
Car.pop("year") |
|
|
The
pop() method removes the item with the specified key name |
|
Car.popitem() |
|
|
The
popitem() method removes the last inserted item |
|
del Car["year"] |
|
|
The
del keyword removes the item with the specified key name |
del Car |
Car.clear() |
|
Example 1
CarCopy = Car.copy() Example 2 CarCopy = dict(Car) |
Cars = { |
|
|
Create a nested dictionary from two existing dictionairies.
|
|
Car1 = { |
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.