所以我试图完成我的标题所暗示的内容。我把他们的名字和乐器存放在一个清单中。我试图将他们的生日改为字符串,以便我可以将其与其他两个列表连接起来。
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.
答案 0 :(得分:1)
您不能只输入leaves(void, 0).
leaves(tree(E,L,R), X) :- leave(L, L1), leave(R, R1).
这样的内容作为裸文。这是一个数学表达式。当Python看到它时,它会立即计算表达式的值,这就是列表中的内容:
10/16/1962
如果您想要日期,则必须使用>>> 10/16/1962
0.00031855249745158003
对象:
date
如果您想将其格式化为>>> from datetime import date
>>> date(1962, 10, 16)
datetime.date(1962, 10, 16)
>>> str(date(1962, 10, 16))
'1962-10-16'
,则必须使用16 October, 1962
:
strftime()
答案 1 :(得分:0)
我认为只有当str
为datetime
s时才需要删除string
:
Birthdates = ['10/16/1962', '3/5/1970', '7/18/1962', '11/1/1962']
然后将字符串转换为datetime并更改输出格式:
from datetime import datetime
New_list = ["{} is the {} and they were born on {:%d, %B %Y}".format(a,b,datetime.strptime(c, '%m/%d/%Y')) for a, b, c in zip(Members, Instruments, Birthdates)]
print ("\n".join(New_list))
Flea is the Bassist and they were born on 16, October 1962
John Frusciante is the Guitarist and they were born on 05, March 1970
Jack Irons is the Drummer and they were born on 18, July 1962
Anthony Kiedis is the Musician and they were born on 01, November 1962