这里有一些看起来有点傻的东西:当我只是手动创建一个列表时很datetime.strptime()
乐意接受月份名称的迭代列表months = ['January','February']
(calendar.month_name
<type 'str'>
损坏的代码:
import datetime
import calendar
for month in calendar.month_name:
print datetime.datetime.strptime(month,"%B")
错误:
ValueError: time data '' does not match format '%B'
工作代码:
import datetime
months = ['January','February','March']
for month in months:
print datetime.datetime.strptime(month,"%B")
结果:
1900-01-01 00:00:00
1900-02-01 00:00:00
1900-03-01 00:00:00
这里发生了什么?这是for
我不熟悉的python循环的行为吗?