学习微软课程代码

from datetime import datetime,timedleta
today = datetime.now()
print('Today is ' + str(today))

# timedelta is used to define a period of time
one_day =timedelta(days=1)
yesterday = today-one_day
print('Yesterday was: ' + str(yesterday))

结果出现错误

经查找后,发现是文件命名问题,于是更改代码

import datetime
today = datetime.datetime.now()
print('Today is ' + str(today))

# timedelta is used to define a period of time
one_day =datetime.timedelta(days=1)
yesterday = today-one_day
print('Yesterday was: ' + str(yesterday))

运行成功。