# Day9 -- Python 百日馬
Day 9 Dictionaries , Nesting and the Secret Auction
重點記錄
### **有的程式語言稱它叫"Hash Table",有的管它叫做"物件"**
1. 建立Dictionary的方法
2. 存取Dictionary元素的方法
3. 新增Dictionary元素的方法
4. 修改Dictionary元素的方法
5. 刪除Dictionary元素的方法
6. 尋找Dictionary元素的方法
### 字典格式 (Dictionary )格式語法:
{Key: Value}
例如:
{"Bug" : "An error in a program that prevents ...."
文字用 "" 包起來,
***Question 1 : 可以中文嗎?***
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."
}
很多個的話, 要用 , "逗號"隔開.
有趣的是, 要列出輸出的某個 key 值, 故意打錯字, 來驗証. 但打錯字, 就當然對不到, 會出現錯字訊息.
***Question 2 那真的有打錯字, 那要如何掩蓋其錯誤訊息?***
--
字典裡可以包陣列、字典。 // 比較難,需要認真了解邏輯
[{
key: [list],
key2:{Dict},
),
{
key: value,
key2: value,
}]
## 字典三重點:陣列/列表,字典,多重
List是用中括號,Dictionary則是使用大括號。Dictionary是由Key及Value之配對組合而成,順序不重要,但Key的大小寫有分別。跟List一樣,並不限定只能放同一種型態的資料。
## **延伸研究:**
1. Tuple
* https://shengyu7697.github.io/python-tuple/
* https://www.learncodewithmike.com/2019/12/python-tuples.html
2. [使用內建函數 dict()](https://medium.com/ccclub/ccclub-python-for-beginners-tutorial-533b8d8d96f3)
# 字典的補充:
- [ ] [Dictionary 基本操作](https://www.learncodewithmike.com/2019/12/python-dictionary.html)
- [ ] [高見龍的 Dictionary 的教學](https://kaochenlong.com/2011/10/13/python-dictionary/)
與會夥伴的補充:
https://www.one-tab.com/page/BcwJ41dpQumfp0pJamf8Vg
![](https://i.imgur.com/MEjkoSI.png)