匿名作业 [英] anonymous assignment
问题描述
有没有告诉python我不在乎价值?
我想今天一年又一天,我想做点什么喜欢:
导入时间
y,None,d,None,None,None,None = time.localtime()
我知道你不能把任何东西分配给None,但我确定你明白了我的意思,
a特殊关键字意味着我不在乎这个价值。在这个
的特殊情况下,必须有一个更好的方式:
d = time.local()
y = d [0]
d = d [1]
谢谢。
Yves。
http://www.SollerS.ca
Is there anyway to tell python I don''t care about a value ?
Say I want today''s year and day, I''d like to do something like:
import time
y, None, d, None, None, None, None = time.localtime()
I know you can''t assign anything to None, but I''m sure you get what I mean,
a special keyword that means I don''t care about this value. In this
particular case, there''s got to be a better way than:
d = time.local()
y = d[0]
d = d[1]
Thanks.
Yves.
http://www.SollerS.ca
推荐答案
Yves Dorfsman< yv ** @ zioup.comwrites:
Yves Dorfsman <yv**@zioup.comwrites:
导入时间
y,None,d,无,无,无,无= time.localtime()
我知道你不能给任何东西分配任何东西,但我相信你能得到我所拥有的东西>
的意思是,一个特殊的关键字,这意味着我不在乎这个价值。
import time
y, None, d, None, None, None, None = time.localtime()
I know you can''t assign anything to None, but I''m sure you get what I
mean, a special keyword that means I don''t care about this value.
你可以使用一个比你忽略的变量名。这是传统的
使用_但它不是一个特殊的关键字,它只是另一个变量名:
y,_ ,d,_,_,_,_,_,_ = time.localtime()
You can just use a variable name than you ignore. It''s traditional to
use _ but it''s not a special keyword, it''s just a another variable name:
y, _, d, _, _, _, _, _, _ = time.localtime()
2008年5月12日星期一02:28:13 GMT >
Yves Dorfsman< yv ** @ zioup.comwrote:
On Mon, 12 May 2008 02:28:13 GMT
Yves Dorfsman <yv**@zioup.comwrote:
特殊情况下,必须有一个更好的方式:
d = time.local()
y = d [0]
d = d [1]
particular case, there''s got to be a better way than:
d = time.local()
y = d[0]
d = d[1]
喜欢这个?
y,d = time.local()[:2]
-
D''Arcy JM Cain< da *** @ druid.net |民主是三只狼
http://www.druid.net/darcy/ |和一只羊投票
+1 416 425 1212(mod#0082)(eNTP)|什么是晚餐。
Like this?
y, d = time.local()[:2]
--
D''Arcy J.M. Cain <da***@druid.net | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what''s for dinner.
Paul Rubin写道:
Paul Rubin wrote:
Yves Dorfsman< yv ** @ zioup.comwrites:
Yves Dorfsman <yv**@zioup.comwrites:
>导入时间
y,无,d,无,无,无,无= time.localtime()
我知道你不能把任何东西分配给None,但我确定你得到了我的意思,一个特殊的关键词意味着我不关心这个价值。
>import time
y, None, d, None, None, None, None = time.localtime()
I know you can''t assign anything to None, but I''m sure you get what I
mean, a special keyword that means I don''t care about this value.
你可以使用一个比你忽略的变量名。这是传统的
使用_但它不是一个特殊的关键字,它只是另一个变量名:
y,_ ,d,_,_,_,_,_,_ = time.localtime()
You can just use a variable name than you ignore. It''s traditional to
use _ but it''s not a special keyword, it''s just a another variable name:
y, _, d, _, _, _, _, _, _ = time.localtime()
但你仍然有一个使用内存的变量没有。我发现
这令人不满意......我不想比较语言,但我发现
perlundef优雅。
Yves。
http://www.SollerS。 ca
这篇关于匿名作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!