Python 字典(Dictionary) setdefault()方法
来源:互联网 发布:淘宝上的银泰是正品吗 编辑:程序博客网 时间:2024/06/03 01:28
描述
Python 字典(Dictionary) setdefault() 函数和get()方法类似, 如果键不已经存在于字典中,将会添加键并将值设为默认值。
语法
setdefault()方法语法:
点击(此处)折叠或打开
- dict.setdefault(key, default=None)
参数
key -- 查找的键值。default -- 键不存在时,设置的默认键值。
返回值
该方法没有任何返回值。
实例
以下实例展示了 setdefault()函数的使用方法:
点击(此处)折叠或打开
- #!/usr/bin/python
- dict = {'Name':'Zara', 'Age': 7}
- print "Value : %s" % dict.setdefault('Age', None)
- print "Value : %s" % dict.setdefault('Sex', None)
点击(此处)折叠或打开
- Value : 7
- Value : None
0 0
- Python 字典(Dictionary) setdefault()方法
- Python 字典(Dictionary) setdefault()方法
- Python字典的setdefault()方法
- Python字典的setdefault()方法
- Python 字典的setDefault()方法
- python 字典的setdefault方法
- python中字典setdefault()方法理解。
- Python 字典setdefault()
- python 字典setdefault操作
- python 字典的 setdefault用法
- python 字典的 setdefault用法
- python 字典的 setdefault用法
- python笔记--字典setdefault()应用
- Python 字典(Dictionary) has_key()方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) items()方法
- 初学者如何查阅自然语言处理(NLP)领域学术资料
- linux command solution for problems
- find the install path of some software in linux (ubuntu)
- manage .deb package in linux (ubuntu) dpkg
- some package command in linux (ubuntu) zip/ tar/ tar.gz/ tar.bz2
- Python 字典(Dictionary) setdefault()方法
- the shutdown command in linux for shutdown in time or reboot
- python 列表/元组/字典
- python 单行注释/多行注释/代码间注释/特殊注释/"""doc String
- 深入理解python之self
- install pysqlite in ubuntu
- ubuntu mentohust solutions summary
- error: sqlite3.h: No such file or directory #include "sqlite3.h"
- python中的接口