Python自学

print("\u4e2d\u56fd\")

报错,语法错误

修改,去掉尾部的\,正确

import datetime
print("now:"+datetime.datetime.now().year)
#输出当前年份

报错,

Traceback (most recent call last):
File "D:/Python/title.py", line 12, in <module>
print("now:"+datetime.datetime.now().year)
TypeError: can only concatenate str (not "int") to str

修改,

print("now:"+str(datetime.datetime.now().year))

进行了int-》str,类型转换,python并不能像java一样,在做拼接的时候自动把类型转换为string类型;

name=input("输入")
print(name+"他的ASCII码为",ord(c))

报错,

NameError: name 'c' is not defined

修改,

未解决。。。。

猜你喜欢

转载自www.cnblogs.com/only666/p/11335608.html