[Day9]-字典(dict)

  • 基本字典
  1. 字典的元素是以”key:value”的方式储存的,可以利用key去找到对应的value,基本格式如下:
    Dict = {key1:value1,key2:value,…….}
    Key通常是使用字串或数字,且每个key都是唯一值,value可以为任何的资料物件
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644UHbcqIQEpm.png
    https://ithelp.ithome.com.tw/upload/images/20210921/201406441tbz8Kc03d.png

  2. 删除字典
    Pop()方法
    https://ithelp.ithome.com.tw/upload/images/20210921/201406444U90ggQiVs.png
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644Zy4bJ1FAHW.png
    Popitem() 可以随机删除
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644117XBtecy0.png
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644YiMg7rzN8i.png

  3. Dict() 有时候会碰到双值序列,可以是dict()转换成字典,第一个就是key,第二个就是value
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644zsCus5ihyN.png
    https://ithelp.ithome.com.tw/upload/images/20210921/201406441bW11fTce2.png

  4. key in dict 验证元素是否存在
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644aqjrjL3esL.png
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644m7Xu5mb3Py.png
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644njDCduJHBp.png
    https://ithelp.ithome.com.tw/upload/images/20210921/20140644SOwcWN3AgN.png


<<:  Day9

>>:  Day21 - ArgoCD 介绍及安装

【Day 05】format 函式

str.format 是在 python 中常用的字串格式化招式,可以控制想要显示的资料型态、正负号...

Day11 - 除噪模型: FCDAE

全连接神经网路的层和层之间,神经元都是互相连接,而层内的神经元彼此没有连接。我们会使用两种 FCDA...

Day06-Scope && Hoisting

前言 在程序语言中了解程序的周期是很重要的。 在昨日我们已经先了解variables的一些规则了,其...

@Day3 | C# WixToolset + WPF 帅到不行的安装包 [使用发布专案的打包方式]

现今 系统架构多数为前後端分离,也有排程与网站分离…等 系统可能有各种分离,这时候我们打包工具必须做...

Day27 - 在 Next.js 如何正确地使用 dynamic import

前言 在 Next.js 有一个很棒的优点是在 /pages 中的页面预设 next build 时...