“Słowniki Pythona” Kod odpowiedzi

Słownik Python

human = {
  "code": "Python",
  "name": "John",
  "age": 32
}

print(human["age"])
#32 :D
The Cat Coder

Słownik w Python

Polygon = {
	"PolygonName" : "Tetrahectaseptadecagon"
	"PolygonSides" : 417
}

print("A", (Polygon["PolygonName"]) "has", (Polygon["PolygonSides"]), "sides")
Rick Astley

Słownik Python

dictionary = {
    "name": "Elie",
    "family name": "Carcassonne",
    "date of born": "01/01/2001",
    "list": ["hey", "hey"]
}
moi_crn

Python Dict

# 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"
}
codingiscool

Słowniki Pythona

#Python dictionaries consists of key value pairs tha
#The following is an example of dictionary
state_capitals = {
    'Arkansas': 'Little Rock',
    'Colorado': 'Denver',
    'California': 'Sacramento',
    'Georgia': 'Atlanta'
}

#Adding items to dictionary
#Modification of the dictionary can be done in similar maner
state_capitals['Kampala'] = 'Uganda' #Kampala is the key and Uganda is the value

#Interating over a python dictionary
for k in state_capitals.keys():
    print('{} is the capital of {}'.format(state_capitals[k], k))
LazFlex

Słowniki Pythona

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
print(thisdict["brand"])
SAMER SAEID

Odpowiedzi podobne do “Słowniki Pythona”

Pytania podobne do “Słowniki Pythona”

Więcej pokrewnych odpowiedzi na “Słowniki Pythona” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu