python中的循环查询

发布于 2025-01-24 12:44:49 字数 556 浏览 3 评论 0原文

嗨,我想对以下代码进行一些解释。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-01-31 12:44:49
  1. =表示分配,而不是平等测试。如果条件。

    不能在中使用。

  2. !=是一个不等式测试,因此循环将运行直到输入“退出”。

  3. ==是一个平等测试。循环永远不会运行。

  1. = means assignment, not equality test. This can not be used in if condition.

  2. != is an inequality test, so the loop will run until "quit" is entered.

  3. == is an equality test. The loop will never run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文