Python 3.x 我不懂python代码的一部分
你能告诉我下面python代码的第6行是怎么写的吗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"
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