首页 > 解决方案 > 不理解python中的部分代码

问题描述

你能告诉我以下python代码的第6行如何。

command = ""
started = False
while True:
    command = input("> ")
    if command == "start":
        if started:       #didnt understand this
            print("Car already started")
        else:
            started = True
            print("Car started ... ready to go")
    elif command == "stop":
        print("Car stopped")
    elif command == "help":
        print('''start - to start the
                 stop - to stop the car
                 quit - to exit''')
    elif command == "quit":
        break
    else:
        print("I don't get it")

标签: python-3.xloopsif-statementwhile-loop

解决方案


第六行说 if started 是Truethen print("Car already started")。它比说简单,但与评估相同或仅if started == True表示相同的意思startedTrueFalse


推荐阅读