python之函数用法fromkeys()
Python 函数 用法
2023-09-11 14:17:15 时间
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法fromkeys() #fromkeys() #说明:用于创建一个新字典,以序列seq中元素做字典的键,value为字典所有键对应的初始值 ''' >>> help(dict.fromkeys) Help on built-in function fromkeys: fromkeys(...) dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v. v defaults to None. ''' #案例 d=[1,2,3] dict={} dict=dict.fromkeys(d) print dict #{1: None, 2: None, 3: None} dict=dict.fromkeys(d,'xiaodeng') #xiaodeng为默认值 print dict #{1: 'xiaodeng', 2: 'xiaodeng', 3: 'xiaodeng'}
相关文章
- Python语法基础_05.函数-下
- Python partial偏函数及用法
- Python chain函数的用法
- python中locals函数用法详解
- python内置函数compile用法详解
- python中repr()函数用法详解
- python函数的用法详解(作用、定义、调用、函数参数、函数返回值、函数说明文档、函数嵌套使用)
- Python内置函数--sorted()
- 超详细,少数人才知道的 Python 函数定义详解
- Python find函数用法和概念
- python之函数用法xrange()
- python之函数用法__setattr__
- python之函数用法setattr(),了解即可
- python之函数用法id(),了解即可
- python之函数用法file()
- Python函数和代码复用
- python fullmatch函数
- 5.python函数
- python之attrgetter函数对对象排序
- python之itemgetter函数:对字典列表进行多键排序
- Python的range、enumerate和zip函数用法
- python第十四课--排序及自定义函数之自定义函数(案例四)
- Python数学函数
- 【图像处理】——Python霍夫变换之直线检测(主要是两个函数Houghlines&HoughlinesP)