In Python, a list stores a collection of different pieces of information as a sequence under a single variable name.
For example: grocery_list = [“Milk”, “Eggs”, “Rice”,
There are few code below:
Learning Python
Lesson 6 : Lists & Dictionaries
List Functions
Simple programming exercises from Codecademy
"""
# Exercise 0 : Appending & List Length
"""
Append 3 more items to the suitcase list.
Then, set list_length equal to the length of suitcase.
"""
suitcase = []
suitcase.append("sunglasses")
# Append 3 more items to the suitcase
suitcase.append("hat")
suitcase.append("shorts")
suitcase.append("shoes")
suitcase.append("beachwear")
suitcase.append("T-Shirt")
suitcase.append("laptop")
# Create a variable called list_length and assign it to the length of suitcase
list_length = len(suitcase)
print "There are %d items in the suitcase." % list_length
print suitcase
Answer found below:
Learning Python
Lesson 6 : Lists & Dictionaries
List Functions
Simple programming exercises from Codecademy
"""
# Exercise 0 : Appending & List Length
"""
Append 3 more items to the suitcase list.
Then, set list_length equal to the length of suitcase.
"""
suitcase = []
suitcase.append("sunglasses")
# Append 3 more items to the suitcase
suitcase.append("hat")
suitcase.append("shorts")
suitcase.append("shoes")
suitcase.append("beachwear")
suitcase.append("T-Shirt")
suitcase.append("laptop")
# Create a variable called list_length and assign it to the length of suitcase
list_length = len(suitcase)
print "There are %d items in the suitcase." % list_length
print suitcase
No comments:
Post a Comment