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一樣,並不限定只能放同一種型態的資料。