Difference between revisions of "Python List Exercises"
From WLCS
(→Directions) |
(→Directions) |
||
Line 12: | Line 12: | ||
# Create a list named wordList that contains the following words: "washington", "lee", "generals", "arlington", "virginia" | # Create a list named wordList that contains the following words: "washington", "lee", "generals", "arlington", "virginia" | ||
− | # Print out the | + | # Print out the first element in wordList |
# Print out the length of the list by using '''len(wordList)''' | # Print out the length of the list by using '''len(wordList)''' | ||
# Print out the last element in wordList by using '''wordList[len(wordList)-1]''' | # Print out the last element in wordList by using '''wordList[len(wordList)-1]''' | ||
# Print out the word "generals" in the list | # Print out the word "generals" in the list | ||
# | # |
Revision as of 08:19, 13 May 2010
Objectives
- You will learn to create lists
- You will learn to access elements (things) in a list
- You will learn to traverse (walk through) a list using a loop
Resources
Directions
Create a file name "ch9_yourLastName.py". In your file, complete the following exercises:
- Create a list named wordList that contains the following words: "washington", "lee", "generals", "arlington", "virginia"
- Print out the first element in wordList
- Print out the length of the list by using len(wordList)
- Print out the last element in wordList by using wordList[len(wordList)-1]
- Print out the word "generals" in the list