Python 字典(Dictionary) get()方法
2015-08-10 22:27
721 查看
描述
Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值。语法
get()方法语法:dict.get(key, default=None)
参数
key -- 字典中要查找的键。default -- 如果指定键的值不存在时,返回该默认值值。
返回值
返回指定键的值,如果值不在字典中返回默认值None。实例
以下实例展示了 get()函数的使用方法:#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 27} print "Value : %s" % dict.get('Age') print "Value : %s" % dict.get('Sex', "Never")
以上实例输出结果为:
Value : 27 Value : Never
相关文章推荐
- 小白学Python(四) 简单的用户管理系统v0.2
- [2015-08-09] python020
- python numpy sum函数用法
- python numpy argsort函数用法
- python __name__用法
- Apriori算法
- 升级MAC OX上的Python到3.4
- 自动化运维工具Ansible之Python API
- machine learning in coding(python):拼接原始数据;生成高次特征
- Python(x,y)科学计算包的安装
- python安装psycopg2
- python基础教程学习笔记 — 准备Windows下开发环境
- python:5、函数2
- Python中的布尔类型
- 实习小记-python中不可哈希对象设置为可哈希对象
- [Python基础]010.os模块(2)
- python:5、函数1
- 《机器学习系统设计》之k-近邻分类算法
- python tile函数用法
- python发送各类邮件的主要方法 smpt