所以我正在努力实现我的标题所暗示的。我把他们的名字和乐器储存在一个列表里。我试图将他们的生日更改为字符串,以便将其与其他两个列表连接起来
Members = ["Flea", "John Frusciante", "Jack Irons", "Anthony Kiedis"]
Instruments = ["Bassist", "Guitarist", "Drummer", "Musician"]
Birthdates = str([10/16/1962, 3/5/1970, 7/18/1962, 11/1/1962])
New_list = [a + " is the " + b + " and they were born on " + c for a, b, c in zip(Members, Instruments, Birthdates)]
print "\n".join(New_list)
我的结果有点混乱,因为我没有收到任何错误。我希望这些日期可以打印出来,因为它们被记录在生日列表中
Flea is the Bassist and they were born on [
John Frusciante is the Guitarist and they were born on 0
Jack Irons is the Drummer and they were born on ,
Anthony Kiedis is the Musician and they were born on
我知道从那时到现在,我缺少了一些步骤,但我的目标如下:
Flea is the Bassist and they were born on 16 October, 1962.
您不能只输入像
10/16/1962
这样的内容作为裸文本。这是一个数学表达式。当Python看到这一点时,它会立即计算表达式的值,这就是列表中的内容:如果需要日期,则必须使用
date
对象:如果要将其格式化为
16 October, 1962
,则必须使用strftime()
:我认为只有当
datetime
是string
时,才需要删除str
:然后将字符串转换为datetime并更改输出格式:
相关问题 更多 >
编程相关推荐