读书人

print(*(time.localtime()))中字符‘*

发布时间: 2013-06-25 23:45:42 作者: rapoo

print(*(time.localtime()))中字符‘*’起什么作用?
我在8.1.8. strftime() and strptime() Behavior中看到
datetime.strptime(date_string, format) is equivalent to
datetime(*(time.strptime(date_string, format)[0:6]))
不知道字符'*'在表达式中的用途。

[解决办法]
func(*arg)的意思是把arg(一个list或其他?)的元素作为参数传给func。


In [188]: def f(x, y):
...: print 'x =', x, ',' 'y =', y
...:

In [189]: f(1,2)
x = 1 ,y = 2

In [190]: f(*[1,2])
x = 1 ,y = 2

In [191]: f(*(1,2))
x = 1 ,y = 2

读书人网 >perl python

热点推荐