Appending จะ dictionart เป็นภาษาไพธอน

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

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
3
0

N

default_data = {'item1': 1,
                'item2': 2,
          	    }

default_data.update({'item3': 3})
# or
default_data['item3'] = 3
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

0
0

N

d = {'a': 1, 'b': 2}
print(d)
d['a'] = 100  # existing key, so overwrite
d['c'] = 3  # new key, so add
d['d'] = 4
print(d)

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

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

ในภาษาอื่นๆ

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

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

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

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