Python While 循环中的赋值条件 [英] Assignment Condition in Python While Loop
本文介绍了Python While 循环中的赋值条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C 中,你可以做到
In C, one can do
while( (i=a) != b ) { }
但在 Python 中,似乎不能.
but in Python, it appears, one cannot.
while (i = sys.stdin.read(1)) != "
":
生成
while (i = sys.stdin.read(1)) != "
":
^
SyntaxError: invalid syntax
(^
应该在 =
上)
有解决方法吗?
推荐答案
使用中断:
while True:
i = sys.stdin.read(1)
if i == "
":
break
# etc...
这篇关于Python While 循环中的赋值条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文