4.5冗余参数处理
(1)、多类型传值(向函数传元组和字典)
example4.5.1
(1)、多类型传值(向函数传元组和字典)
example4.5.1
>>> def f(x):
print(x)
>>> #传递元组
>>> f(range(10))
range(0, 10)
>>> f([1,2,3,4])
[1, 2, 3, 4]
>>> #传递字典
>>> f({1:111,2:222,3:333})
{1: 111, 2: 222, 3: 333}
example4.5.2
>>> def f(x,y):
print(x,y)
>>> t=('a','b')
>>> f(t)
Traceback (most recent call last):
File "<pyshell#94>", line 1, in <module>
f(t)
TypeError: f() missing 1 required positional argument: 'y'
>>> f(t,'test')
('a', 'b') test
>>>
example4.5.3
#格式化字符串说明
>>> print("%s:%s"%(13,14))
13:14
example4.5.3