Chapter 10. Dictionaries (learnpython.org)
1. How to define a dictionary
phonebook = {}
phonebook["John"] = 938477566
phonebook["Jack"] = 938377264
phonebook["Jill"] = 947662781
phonebook = {
"John" : 938477566,
"Jack" : 938377264,
"Jill" : 947662781
}
2. Iterating over dictionaries
phonebook = {"John" : 938477566,"Jack" : 938377264,"Jill" : 947662781}
for name, number in phonebook.items():
print("Phone number of %s is %d" % (name, number))
# print
'''
Phone number of Jill is 947662781
Phone number of John is 938477566
Phone number of Jack is 938377264
'''
3. Removing a value
del phonebook["John"]
phonebook.pop("John")
Exercise
'IT World > Python' 카테고리의 다른 글
Python Training Day 9. Numpy Arrays (0) | 2022.12.20 |
---|---|
Python Training Day 8. Modules and Packages (0) | 2022.12.19 |
Python Training Day 6. Classes and Objects (0) | 2022.12.17 |
Python Training Day5. Functions (0) | 2022.12.16 |
Python Training Day4. Loops (0) | 2022.12.15 |
댓글