Difference between revisions of "Python String Exercises"
From WLCS
Line 1: | Line 1: | ||
− | Directions | + | == Objective == |
+ | * You will learn to create and access characters and slices of a string | ||
+ | * You will learn to use a loop to traverse the characters of a string | ||
+ | |||
+ | == Directions == | ||
+ | * Create a python file named ch7_YOURLASTNAME.py | ||
# Create a string "The quick brown fox jumped over the lazy dog." in a variable s | # Create a string "The quick brown fox jumped over the lazy dog." in a variable s |
Revision as of 08:06, 13 May 2010
Objective
- You will learn to create and access characters and slices of a string
- You will learn to use a loop to traverse the characters of a string
Directions
- Create a python file named ch7_YOURLASTNAME.py
- Create a string "The quick brown fox jumped over the lazy dog." in a variable s
- Print out the first letter in s using the brackets (e.g. s[NUM])
- Print out the letter "q" using s and the index 4
- Print out the letter "x" using s and the corresponding index
- Using string slicing, print out the word "brown"
- Using string slicing, print out the word "lazy"
- Using string slicing, print out starting at the word "jumped" through the end of the string
- Use the string variable s from Question 1. Create a loop that prints out every letter in the variable s
- Use the string variable s from Question 1. Create a loop that prints out every letter in s backwards starting from the end.
- Use the string variable s from Question 1. Create a loop that prints out every other letter in s starting from the beginning