pizzas = ["hawai","salame","vegetable","capriciosa","new york"]
for pizza in pizzas:
print("I like " + pizza.title() + " pizza!")
print("\n" + "The first three pizzas in the list are: " + str(pizzas[0:3]))
print("\n" + "The last three pizzas in the list are: " + str(pizzas[-1:-3]))
I get:
I like Hawai pizza!
I like Salame pizza!
I like Vegetable pizza!
I like Capriciosa pizza!
I like New York pizza!
The first three pizzas in the list are: ['hawai', 'salame', 'vegetable']
The last three pizzas in the list are: []
and I'm puzzled. Isn't -1
indicating the last element in the list ? I'm indexing [start:stop]
so shouldn't it print my the last 3 items ? What am I doing wrong ?