Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # dicionary => key : value
- # tanda kurung { }
- # object
- student = {"name": "Jaka", "address": "Jakarta Barat"}
- car = {
- "model": "truck",
- "brand": "ford",
- "year": 2010,
- "color1": ["red", "blue", "black"],
- }
- # display dict keys
- print(car.keys())
- # access item
- print(car["brand"])
- # add new item
- car["owner"] = "Jaka"
- print(car)
- # modify item
- car["year"] = 2011
- print(car)
- # modify item
- car["color"] = ["red", "black"]
- print(car)
- # remove item
- car.pop("color")
- print(car)
- # remove the last item
- car.popitem()
- print(car)
Advertisement
Add Comment
Please, Sign In to add comment