语法无效:无,第4行,位置72

时间:2013-10-19 20:14:56

标签: python date space

我不能在一年到一小时之间留出空间,我不能使用“,”。我使用串联。

from datetime import datetime
now = datetime.now()

print str(now.month) + "/" + str(now.day) + "/" + str(now.year), "+ "str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)

3 个答案:

答案 0 :(得分:1)

 + str(now.year), "+ "str(now.hour) + ":"

您的+在引号中,并且在str(now.year)

之后有逗号

答案 1 :(得分:1)

尝试避免这样长的语句,并尝试以可读的方式格式化它们。您错误地将+运算符放在""内,并且我认为,应该打印为月/日/年小时之间的分隔符:分钟:秒

print str(now.month) + "/" + 
      str(now.day) + "/" + 
      str(now.year) + " " +
      str(now.hour) + ":" + 
      str(now.minute) + ":" + 
      str(now.second)

答案 2 :(得分:0)

now.strftime('%m/%d/%Y + %H:%M:%S')

在'now = datetime.now()'之后键入此命令,您将获得所需的输出。