首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

print(*(time.localtime()))中字符‘*’伏什么作用

2013-06-25 
print(*(time.localtime()))中字符‘*’起什么作用?我在8.1.8. strftime() and strptime() Behavior中看到da

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

热点排行