“bagaimana mendefinisikan kamus dalam python” Kode Jawaban

Kamus dalam Python

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

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

Kamus dalam Python

#a dictionary
dict = {
  "key": "value",
  "other_key": "value"
}

#get a value from the dictionary using the key
print(dict["key"])

#you can also get a value from the dictionary using a normal index:
print(dict[1])
Poor Pony

bagaimana mendefinisikan kamus dalam python

population = {"Shanghai":17.8, "Istanbul":13.3, "Karachi":13.0, "Mumbai":12.5}

#Consider the following when creating a dictionary
#	1. Must be inside {}
#	2. Have two parts in an item 
#			Key - e.g. Istanbul and Value - e.g. 13.3
#	3. There must be a colon ":" between the key and the value
#	4. Item must be seperated by commas ","
#	3. Any immutable type can be used as keys (not only integers like in lists)
Rajitha Amarasinghe

Kamus dalam Python

Dict = {"name": 'Izhaan', "salary": 1234, "age": 23} 
print("\nDictionary with the use of string Keys: ") 
print(Dict)
Bored Buzzard

Jawaban yang mirip dengan “bagaimana mendefinisikan kamus dalam python”

Pertanyaan yang mirip dengan “bagaimana mendefinisikan kamus dalam python”

Lebih banyak jawaban terkait untuk “bagaimana mendefinisikan kamus dalam python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya