Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我不懂python代码的一部分_Python 3.x_Loops_If Statement_While Loop - Fatal编程技术网

Python 3.x 我不懂python代码的一部分

Python 3.x 我不懂python代码的一部分,python-3.x,loops,if-statement,while-loop,Python 3.x,Loops,If Statement,While Loop,你能告诉我下面python代码的第6行是怎么写的吗 command = "" started = False while True: command = input("> ") if command == "start": if started: #didnt understand this print("Car already started"

你能告诉我下面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")

第六行表示如果启动为
True
,则
打印(“汽车已启动”)
。这比说
if started==True
更简单,但意思与
started
计算为
True
False
的值相同,只是

您不理解的内容>但是我们给变量start的值为False。因此,当我们键入if started时:它不是意味着if false吗?是的,但一旦您启动汽车并输入
start
命令
started
将等于
false
,然后if语句将变为
if true