- 主题:Python的循环结束else分支语义与英文意思间有点别扭吧?
Python的循环结束else分支语义与英文意思间有点别扭吧?
为什么用else这个关键词?
我觉得loopdone不错
--
FROM 112.50.55.*
def fn(ls):
dict1={}
for i in ls:
dict1[i]=dict1.get(i,0)+1
for c in dict1.values():
if c>1:
return True #假如印刷到页尾
else: #新的一页
return False
这段代码,如果印刷到书本,那个else很容易被误以为和if配套,而不是和for配套
--
修改:ooolinux FROM 183.251.227.*
FROM 183.251.227.*
for else有点怪
while else很正常
【 在 ooolinux 的大作中提到: 】
: Python的循环结束else分支语义与英文意思间有点别扭吧?为什么用else这个关键词?我觉得loopdone不错 ...
--
FROM 124.14.49.*
while xxx:
a
else:
b
应该非a即b,实际上相反
【 在 ToSimplicity 的大作中提到: 】
: for else有点怪
: while else很正常
--
FROM 183.251.227.*
当循环条件不满足时就走else,loopdone肯定不合适啊
--
FROM 60.191.227.*
nobreak的时候走else
【 在 freesand 的大作中提到: 】
: 当循环条件不满足时就走else,loopdone肯定不合适啊
--
修改:ooolinux FROM 183.251.227.*
FROM 183.251.227.*
用then更合理
【 在 ooolinux 的大作中提到: 】
: nobreak的时候走else
--
FROM 116.23.28.*
‘然后’,可以
【 在 iMx 的大作中提到: 】
: 用then更合理
:
--
FROM 183.251.227.*
for else is abusolutly ugly
【 在 ooolinux 的大作中提到: 】
: Python的循环结束else分支语义与英文意思间有点别扭吧?
: 为什么用else这个关键词?
: 我觉得loopdone不错
--
FROM 14.154.189.*
相对来说
【 在 lookforit 的大作中提到: 】
: for else is abusolutly ugly
--
FROM 183.251.227.*