Python入门:列表、字典拆分参数

来源:互联网 发布:mac虚拟机怎么全屏 编辑:程序博客网 时间:2024/06/04 23:23

列表拆分参数

>>> list(range(3,6))[3, 4, 5]>>> args = [3,6]>>> list(range(args))Traceback (most recent call last):  File "<input>", line 1, in <module>TypeError: 'list' object cannot be interpreted as an integer>>> list(range(*args))[3, 4, 5]

字典拆分参数

def people(name,age='0',sex='m'):    print(name,age,sex)d = {'name':'slg','age':10,'sex':'f'}people(**d)

运行结果

slg 10 f

补充

def people(name,age='0',sex='m'):    print(name,age,sex)d = {'name':'slg','age':10,'sex':'f'}people(*d)  #此处使用一个‘*’的是字典参数,看看会出现什么结果

运行结果

name age sex
0 0
原创粉丝点击