티스토리 뷰

딕셔너리: key, value

중첩

 

 

* Dictionary

    { key : value }

    { key1:value1, key2:value2, ... }

    키는 "문자", 숫자 123, 등 datatype을 구별한다

 

# Retrieving items for dictionary

programming_dictionary = {
    "Bug": "An error in a program that prevents the program from running as expected.",
    "Function": "A piece of code that you can easily call over and over again.",
    "Loop": "The action of doing something over and over again.",
}
print(programming_dictionary["Function"])
--------------------------------------------------------------------------------------------------
A piece of code that you can easily call over and over again.
 
# Adding new items to dictionary
programming_dictionary["kio"] = "Hansome guy in south Korea."
print(programming_dictionary)
--------------------------------------------------------------------------------------------------
{'Bug': 'An error in a program that prevents the program from running as expected.', 'Function': 'A piece of code that you can easily call over and over again.', 'Loop': 'The action of doing something over and over again.', 'kio': 'Hansome guy in south Korea.'}

 

# Create an empty dictionary

empty_dictionary = {}

 

# Wipe an existing dictionary

programming_dictionary = {}

 

# Edit an item in a dictionary

programming_dictionary["kio"] = "Really hansome" 

 

# Loop through a dictionary

for key in programming_dictionary :
print(key)
----------------------------------------------------------------------------------------------------------
Bug
Function
Loop
kio

for key in programming_dictionary :
    print(key)
    print(programming_dictionary[key]
----------------------------------------------------------------------------------------------------------
Bug
An error in a program that prevents the program from running as expected.
Function
A piece of code that you can easily call over and over again.
Loop
The action of doing something over and over again.
kio
Hansome guy in south Korea.

    

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함