Python

4 Python Lists – Copying Lists

Copying List

COPYING LIST code

print(“Copying list from one to another”)
my_favorite_foods = [‘pizza’, ‘rice’, ‘cake’]
friends_favorite_foods = my_favorite_foods[:]
print(“My favorite foods are:”)
print(my_favorite_foods)
print(“\nMy friend’s favorite foods are:”)
print(friends_favorite_foods)

Results:

Copying list from on to another
My favorite foods are:
['pizza', 'rice', 'cake']
My friend's favorite foods are:
['pizza', 'rice', 'cake']
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s