Python 这并不意味着';好像不行。“没有错误消息或任何东西。”;时间“;只是没有';不要打印。现在和分秒都显示正确的值。
这里一切都很好Python 这并不意味着';好像不行。“没有错误消息或任何东西。”;时间“;只是没有';不要打印。现在和分秒都显示正确的值。,python,Python,这里一切都很好 from datetime import datetime while True: now = str(datetime.now()) decisecond = now[20] 这部分不行 if decisecond == 1: print(time) 这是因为'decisecond'不是int。将if语句更改为此,它将工作: if int(decisecond) == 1: print(time) 这么说来,打印“
from datetime import datetime
while True:
now = str(datetime.now())
decisecond = now[20]
这部分不行
if decisecond == 1:
print(time)
这是因为'decisecond'不是int。将if语句更改为此,它将工作:
if int(decisecond) == 1:
print(time)
这么说来,打印“时间”不会打印出我认为你想要的东西。可能会将其更改为打印日期时间,因此整个代码是:
从日期时间导入日期时间
while True:
now = str(datetime.now())
decisecond = now[20]
if int(decisecond) == 1:
print(datetime.now())
欢迎来到StackOverflow。请编辑主题行以描述问题。“这不管用”适用于这里发布的大多数问题!尝试“如何用python打印时间”之类的内容