Appending
Appending: Code
#APPENDING TO LIST
print("Copying list from one to another")
my_favorite_foods = ['pizza', 'rice', 'cake']
friends_favorite_foods = my_favorite_foods[:]
#APPEND
print("Append new food items")
my_favorite_foods.append('fruits')
friends_favorite_foods.append('ice cream')
Print
print("My favorite foods are:")
print(my_favorite_foods)
print("\nMy friend's favorite foods are:")
print(friends_favorite_foods)
Results:
Append new food items
My favorite foods are:
['pizza', 'rice', 'cake', 'fruits', 'ice cream']
My friend's favorite foods are:
['pizza', 'rice', 'cake', 'fruits', 'ice cream']
Like this:
Like Loading...
Related