Python内置函数
- Python内置函数- __import__() 函数
- Python内置函数- zip()函数
- Python内置函数-vars()函数
- Python内置函数-type()函数
- Python内置函数-tuple 函数
- Python内置函数-super()函数
- Python内置函数-sum()函数
- Python内置函数-str()函数
- Python内置函数-staticmethod()函数
- Python内置函数-sorted()函数
- Python内置函数-slice()函数
- Python内置函数-setattr()函数
- Python内置函数-set() 函数
- Python内置函数-round()函数
- Python内置函数-reversed函数
- Python内置函数-repr()函数
- Python内置函数-range() 函数
- Python内置函数-property() 函数
- Python内置函数-print() 函数
- Python内置函数-pow() 函数
- Python内置函数-ord()函数
- Python内置函数-open()函数
- Python内置函数-oct() 函数
- Python内置函数-next() 函数
- Python内置函数-min() 函数
- Python内置函数-memoryview() 函数
- Python内置函数-max() 函数
- Python内置函数-map()函数
- Python内置函数-locals() 函数
- Python内置函数-list()函数
- Python内置函数-len()函数
- Ptyhon内置函数-iter()函数
- Python内置函数-issubclass()函数
- Python内置函数-isinstance() 函数
- Python内置函数-int() 函数
- Python内置函数-input()函数
- Python内置函数-id()函数
- Python内置函数-hex()函数
- Python内置函数-help()函数
- Python内置函数-hash() 函数
- Python内置函数-hasattr() 函数
- Python内置函数-globals() 函数
- Python内置函数-getattr() 函数
- Python内置函数-frozenset() 函数
- Python内置函数-format()函数
- Python内置函数-float()函数
- Python内置函数-filter()函数
- Python内置函数-exec()函数
- Python内置函数-eval()函数
- Python内置函数-enumerate() 函数
- Python内置函数-divmod()函数
- Python内置函数-dir()函数
- Python内置函数-dict()函数
- Python内置函数- delattr()函数
- Python内置函数-complex()函数
- Python内置函数-compile() 函数
- Python内置函数-classmethod()函数
- Python内置函数-chr() 函数
- Python内置函数-callable() 函数
- Python内置函数-bytes函数
- Python内置函数-bytearray() 函数
- Python内置函数-bool()函数
- Python内置函数-bin() 函数
- Python内置函数-ascii()函数
- Python内置函数-any() 函数
- Python内置函数-all() 函数
- Python内置函数-abs() 函数
- Python内置函数-大全
Python内置函数-dict()函数
Python3内置函数--dict()
dict()函数描述:
dict() 函数用于创建一个字典。
dict()函数语法:
class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
dict()函数参数:
**kwargs -- 关键字
mapping -- 元素的容器。
iterable -- 可迭代对象。
dict()函数返回值:
返回一个字典。
dict()函数实例:
# 创建空字典方法1 d = dict() print(type(d)) # <class 'dict'> # 创建空字典方法2 d2 = {} print(type(d2)) # <class 'dict'> # 创建一个标准的字典 dict2 = {'name':'bayi','age':33} print(type(dict2)) # <class 'dict'> print(dict2) # {'name': 'bayi', 'age': 33} # 创建一个传入 关键字=值 的字典 dict3 = dict(name='bayi', age=33, sex='男') print(type(dict3)) # <class 'dict'> print(dict3) # {'name': 'bayi', 'age': 33, 'sex': '男'} # 映射函数方式来构造字典 dict4 =dict(zip(['name','age','address'],['bayi',33,'广东'])) print(type(dict4)) # <class 'dict'> print(dict4) # {'name': 'bayi', 'age': 33, 'address': '广东'} # 可迭代对象(能用for循环的对象)方式来构造字典 # Python中的可迭代对象有:列表、元组、字典、字符串; # dict5 = dict([['one',1],['two',2],['three',3]]) # 方式1 # dict5 = dict([('one',1),('two',2),('three',3)]) # 方式2 # dict5 = dict((('one',1),('two',2),('three',3))) # 方式3 dict5 = dict((['one',1],['two',2],['three',3])) # 方式4 print(type(dict5)) # <class 'dict'> print(dict5) # {'one': 1, 'two': 2, 'three': 3}
最后修改:2020年3月19日 23:03