วิธีที่จะเพิ่มเข้าไป dictionar ภาษาไพธอน

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

10
0

N

# to add key-value pairs to a dictionary:

d1 = {
	"1" : 1,
	"2" : 2,
  	"3" : 3
} # Define the dictionary

d1["4"] = 4 # Add key-value pair "4" is key and 4 is value

print(d1) # will return updated dictionary
1
0

N

# Append to Dictionary in Python

# Let's say we had the following dictionary:

languages = {'#1': "Python", "#2": "Javascript", "#3": "HTML"}

# There are two ways to add a key-and-value set to this dictionary

# Number 1: By .update() method

languages.update({"#4": "C#"}) # Adds a #4 key-and-value set

#--------------------------------------------

# Number 2: The define-key method

# This is the easier one

languages['#4'] = 'C#'

# ^^ Just updates a key of #4 to C#, or adds it in this case

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

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

ในภาษาอื่นๆ

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

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