In Python, a list stores a collection of different pieces of information as a sequence under a single variable name.
Check out this little code.
suitcase = []
suitcase.append("sunglasses")
# Append 3 more items to the suitcase
suitcase.append("hat")
suitcase.append("shorts")
suitcase.append("shoes")
suitcase.append("camera")
suitcase.append("shaver")
suitcase.append("Tablet")
# 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
suitcase.append("sunglasses")
# Append 3 more items to the suitcase
suitcase.append("hat")
suitcase.append("shorts")
suitcase.append("shoes")
suitcase.append("camera")
suitcase.append("shaver")
suitcase.append("Tablet")
# 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