Python中的时间和日历
我的代码是-Python中的时间和日历,python,python-3.x,Python,Python 3.x,我的代码是- import time; ticks = time.time() print "Output is :", ticks import calendar cal = calendar.month(2014, 1) print "Here is the calendar:" print cal; 对于日历,我的代码是- import time; ticks = time.time() print "Output is :", ticks import calen
import time;
ticks = time.time()
print "Output is :", ticks
import calendar
cal = calendar.month(2014, 1)
print "Here is the calendar:"
print cal;
对于日历,我的代码是-
import time;
ticks = time.time()
print "Output is :", ticks
import calendar
cal = calendar.month(2014, 1)
print "Here is the calendar:"
print cal;
但显示无效语法。为什么?您的
打印功能出错。您正在遵循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
在Python3.x中,print是一个函数。在2.x中,它是一个表达式。@Neo必须用分号分隔代码>而非,
即导入日历;cal=日历月(2014年1月);打印(cal)代码>谢谢@Bhargav Rao。我是python新手。所以我在简单的部分面临很多问题。去掉后面的分号@谢天谢地,Python开发人员考虑了代码>