my_foods = ['pizza','falafel','carrot cake','olio']
friend_foods = my_foods[:]
my_foods.append('cannoli')
friend_foods.append('ice cream')
print("my favorite foods are:")
print(my_foods)
print("my friend's favorite foods are:")
print(friend_foods)
print("The first three items in the list are:")
print(my_foods[0:3]+'\n') 这里出粗了
print("The middle three items in the list are:")
print(my_foods[1:4]+'\n')
print("The last three items in the list are:")
print(my_foods[-3:]+'\n')
出现这样的错误是因为你试图将一个列表与一个非列表类型的值(无论是什么类型:换成一个单个字符串也会有同样的错误)连接,这是不允许的。列表连接两边必须都为列表(list)
?????????