Python3?????? dict pop ?????????????????????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3?????? dict pop ?????????????????????相关的知识,希望对你有一定的参考价值。

???????????????   ??????   error:   ??????   inf   exit   activate   ide   res   

?

  • ???????Python : 3.7.0
  • ?????????OS : Ubuntu 18.04.1 LTS
  • ????????IDE : PyCharm 2018.2.4
  • ??????Conda : 4.5.11
  • ???typesetting : Markdown

?

code

[email protected]:~$ source activate py37
(py37) [email protected]:~$ ipython
Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: my_dic = {'???': '???', '???': '???', '???': '???', '???': '???',
   ...:           '???': '???', '???': '???', '???': '???', '???': '???',
   ...:           '???': '???', '???': '???', '???': '???', '???': '???'}
   ...:           

In [2]: # ?????? ?????? '???'??????

In [3]: my_dic.pop('???')
Out[3]: '???'

In [4]: my_dic
Out[4]: 
{'???': '???',
 '???': '???',
 '???': '???',
 '???': '???',
 '???': '???',
 '???': '???',
 '???': '???',
 '???': '???',
 '???': '???',
 '???': '???',
 '???': '???'}

In [5]: # ?????? ?????????????????????????????????????????????

In [6]: my_dic.pop('?????????')
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-816ff248824b> in <module>()
----> 1 my_dic.pop('?????????')

KeyError: '?????????'

In [7]: exit
(py37) [email protected]:~$ source deactivate
[email protected]:~$ 

?

resource

  • [??????] docs.python.org/3
  • [??????] www.python.org/dev/peps/pep-0008
  • [??????] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
  • [??????] www.python.org/downloads/source
  • [ PEP ] www.python.org/dev/peps
  • [??????] www.cnblogs.com
  • [??????] gitee.com

?


Python???????????????????????????????????????????????????????????????????????????
Python??????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????

以上是关于Python3?????? dict pop ?????????????????????的主要内容,如果未能解决你的问题,请参考以下文章

python 类

python面向对象补充

Python dict get items pop update

Python3---内建函数---dict()

Python - 字典(dict)删除元素

Python - 字典(dict)删除元素