Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.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 这并不意味着';好像不行。“没有错误消息或任何东西。”;时间“;只是没有';不要打印。现在和分秒都显示正确的值。_Python - Fatal编程技术网

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打印时间”之类的内容