【发布时间】:2019-11-24 17:07:20
【问题描述】:
我尝试使用函数的参数作为列表索引,但是我得到了
TypeError:列表索引必须是整数或切片,而不是元组。
days=['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh']
gifts=['and a patriage in a Pear tree', 'two Turtle Doves', 'three French Hens', 'four Calling Birds', 'five Gold Rings', 'six Geese-a-Laying', 'seven Swans-a-Swimming', 'eigth Maids-a-Milking', 'nine Ladies Dancing', 'ten Lords-a-Leaping', ' eleven Pipers Piping', 'twelve Drummers Drumming']
def recite( start_verse, end_verse):
return ('On the '+days[start_verse+1] + ' day of Christmas my true love gave to me: '+ gifts[-1, end_verse])
print(recite(2,2))
【问题讨论】:
-
欢迎来到 Stack Overflow!查看tour。
-
您期待列表中的一部分吗?为此尝试
gifts[end_verse-1::-1]
标签: python python-3.x list