GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dict pop · enoughbr/StarterLearningPython@9357bcf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • 117.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎117.md‎

Copy file name to clipboardExpand all lines: 117.md
+3-1Lines changed: 3 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ get的含义是:
317317
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
318318
If key is not found, d is returned if given, otherwise KeyError is raised
319319

320-
`D.pop(k[,d])`是以字典的键为参数,删除指定键的键值对,当然,如果输入对应的值也可以,那个是可选的。
320+
`D.pop(k[,d])`是以字典的键为参数,删除指定键的键值对。
321321

322322
>>> dd
323323
{'lang': 'python', 'web': 'www.itdiffer.com', 'name': 'qiwsir'}
@@ -343,6 +343,8 @@ get的含义是:
343343
File "<stdin>", line 1, in <module>
344344
KeyError: 'name'
345345

346+
`pop`的参数,可以是两个,上面的例子中只写了一个。如果写两个,那么就先检查k是不是存在于字典中的键,如果是,就返回它所对应的值,如果不是,就返回参数中的第二个,当然,如果不写第二个参数,就会如同上面举例一样报错。
347+
346348
有意思的是`D.popitem()`倒是跟`list.pop()`有相似之处,不用写参数(list.pop是可以不写参数),但是,`D.popitem()`不是删除最后一个,前面已经交代过了,dict没有顺序,也就没有最后和最先了,它是随机删除一个,并将所删除的返回。
347349

348350
popitem(...)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.