วิธีที่จะได้พจนานุกรมค่าภาษาไพธอน

รหัสตัวอย่าง

32
0

ปลั๊กอินสำหรับไพธอนพจนานุกรม

#title			:Dictionary Example
#author         :Josh Cogburn
#date           :20191127
#github         :https://github.com/josh-cogburn
#====================================================

thisdict = {
	"brand": "Ford",
 	"model": "Mustang",
 	"year": 1964
}

#Assigning a value
thisdict["year"] = 2018
9
0

ปลั๊กอินสำหรับไพธอนได้ค่าจากพจนานุกรม

dict = {'color': 'blue', 'shape': 'square', 'perimeter':20}
dict.get('shape') #returns square

#You can also set a return value in case key doesn't exist (default is None)
dict.get('volume', 'The key was not found') #returns 'The key was not found'
4
0

การพิมพ์เป็นภาษาไพธอนพจนานุกรมค่า

#print keys and values from the dictionary

for k, v in dic.items():
  print(k, v)
2
0

รายการของพจนานุกรมค่า

d.values()
1
0

มีค่ามาจากพจนานุกรมภาษาไพธอน

#!/usr/bin/python

dict = {'Name': 'Zabra', 'Age': 7}
print "Value : %s" %  dict.get('Age')
print "Value : %s" %  dict.get('Education', "Never")
0
0

ยังไงเพื่อให้คุณค่าจากกุญแจ dict ภาษาไพธอน

# Get a value from a dictionary in python from a key

# Create dictionary
dictionary = {1:"Bob", 2:"Alice", 3:"Jack"}

# Retrieve value from key 2
entry = dictionary[2]

# >>> entry
# Alice

หน้าคล้ายกัน

คล้ายกันหน้ากับตัวอย่าง

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังหน้ากับตัวอย่างอยู่ในหมวดหมู่