python-3.x - 不理解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")
解决方案
第六行说 if started 是True
then print("Car already started")
。它比说简单,但与评估相同或仅if started == True
表示相同的意思started
True
False
推荐阅读
- macros - Flask-WTF,使用宏使用 {{ field |safe}} 的意外输出(HTML 转义)
- javascript - 切换导航栏未显示列表元素
- php - PHP,无需等待执行就将控制权发送给另一个代码
- c++ - C++ 11 Boost 1.65 recursive_directory_iterator 给出分段错误错误
- node.js - NodeJS - 仅将 OPTIONS 请求发送到 REST API,不遵循 POST 或 GET (Cloudflare)
- c# - 如何使用代码优先 mvc5 从本地数据库更改更新实时服务器中的数据库
- c# - 元素不可点击另一个元素接收点击 - Selenium c#
- facebook - GET Facebook Page Post Video Source 不起作用
- docker - 如何确保 docker 容器具有所需的网络接口
- vb.net - 使用 vb.net 创建 SOAP 请求