Python 中的时间和日历

Time and calendar in Python

暂时我的代码是-

import time;  

ticks = time.time()
print "Output is :", ticks 

对于日历,我的代码是-

import calendar

cal = calendar.month(2014, 1)
print "Here is the calendar:"
print cal;

但显示无效语法。为什么?

您的 print 函数有误。您正在遵循 Python2 语法。在 Python3 中,print 是一个函数,与 Python2 不同。

应该是

print("Output is :", ticks)
print(cal)
print("Here is the calendar:")

相反。

除此之外,其他都很好。事实上,如果你在 Py2 中 运行 这个,你将得到输出。

Output is : 1423394876.34    
Here is the calendar:
    January 2014
Mo Tu We Th Fr Sa Su
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31