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

有哪位高手可以解读一下该语句的含义:datetime(*time.localtime()[:6])

2012-06-28 
有谁可以解读一下该语句的含义:datetime(*time.localtime()[:6])有谁可以解读一下该语句的含义:datetime(*

有谁可以解读一下该语句的含义:datetime(*time.localtime()[:6])
有谁可以解读一下该语句的含义:datetime(*time.localtime()[:6]),尤其是*号的含义是什么?

[解决办法]
*是序列展开,每个元素都当做一个参数。
ls = (1, 2, 3);
foo(ls),这样foo只有一个参数,就是ls这个列表本身
foo(*ls), foo得到3个参数,分别为1 2 3
[解决办法]
最新的 python 版本中,在调用函数式能够使用 * 语法,它会解包参数集合

Python code
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32Type "copyright", "credits" or "license()" for more information.>>> def func(a, b, c, d):    print(a, b, c, d)    >>> args = (1, 2)>>> args += (3, 4)>>> func(*args)(1, 2, 3, 4)>>> 

热点排行