python中的循环查询
嗨,我想对以下代码进行一些解释。
1。
command = ''
while command = "quit":
command = input('>')
print('ECHO',command)
文件“”,第2行 而命令=“ quit”: ^ SyntaxError:无效的语法,
当我使用a!='quit'运行相同的代码时: 程序运行 2。
command = ''
while command != "quit":
command = input('>')
print('ECHO',command)
command = ''
while command == "quit":
command = input('>')
print('ECHO',command)
我想知道为什么第一代码在运行第二代码时会遇到错误,以及为什么第三代码未获取对话框输入输入。
Hi I would like some explanation to the below code.
1.
command = ''
while command = "quit":
command = input('>')
print('ECHO',command)
File "", line 2
while command = "quit":
^
SyntaxError: invalid syntax
When I run the same code with a != 'quit' :
the program runs
2.
command = ''
while command != "quit":
command = input('>')
print('ECHO',command)
command = ''
while command == "quit":
command = input('>')
print('ECHO',command)
I would like to know why the 1st code is getting the error while the 2nd is running and why the 3rd code is not getting the dialog box to enter the input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
=
表示分配,而不是平等测试。如果条件。不能在
中使用。
!=
是一个不等式测试,因此循环将运行直到输入“退出”。==
是一个平等测试。循环永远不会运行。=
means assignment, not equality test. This can not be used inif
condition.!=
is an inequality test, so the loop will run until "quit" is entered.==
is an equality test. The loop will never run.