Kamus Python
human = {
"code": "Python",
"name": "John",
"age": 32
}
print(human["age"])
#32 :D
The Cat Coder
human = {
"code": "Python",
"name": "John",
"age": 32
}
print(human["age"])
#32 :D
# dict comprehension we use same logic, with a difference of key:value pair
# {key:value for i in list}
fruits = ["apple", "banana", "cherry"]
print({f: len(f) for f in fruits})
#output
{'apple': 5, 'banana': 6, 'cherry': 6}
Polygon = {
"PolygonName" : "Tetrahectaseptadecagon"
"PolygonSides" : 417
}
print("A", (Polygon["PolygonName"]) "has", (Polygon["PolygonSides"]), "sides")
dictionary = {
"name": "Elie",
"family name": "Carcassonne",
"date of born": "01/01/2001",
"list": ["hey", "hey"]
}
# A dict (dictionary) is a data type that store keys/values
myDict = {"name" : "bob", "language" : "python"}
print(myDict["name"])
# Dictionaries can also be multi-line
otherDict {
"name" : "bob",
"phone" : "999-999-999-9999"
}
myDict = {
"Fast": "In a Quick Manner",
"Hasya": "A Coder",
"Marks": [1, 2, 5],
"anotherdict": {'hasya': 'Player'}
}
# print(myDict['Fast'])
# print(myDict['Hasya'])
myDict['Marks'] = [45, 78]
print(myDict['Marks'])
print(myDict['anotherdict']['hasya'])