本文介绍了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)) != "\n":
产生
while (i = sys.stdin.read(1)) != "\n":
^
SyntaxError: invalid syntax
(^
应该在=
上)
有解决方法吗?
推荐答案
使用中断:
while True:
i = sys.stdin.read(1)
if i == "\n":
break
# etc...
这篇关于Python While循环中的分配条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!