This presentation is a part of the COP2271C college level course taught at the Florida Polytechnic University located in Lakeland Florida. The purpose of this course is to introduce Freshmen students to both the process of software development and to the Python language.
The course is one semester in length and meets for 2 hours twice a week. The Instructor is Dr. Jim Anderson.
A video of Dr. Anderson using these slides is available on YouTube at:
http://youtu.be/jGKUAQpRBZw
1. An Introduction To Software
Development Using Python
Spring Semester, 2014
Class #13:
Processing Strings
2. Processing Strings
• One of the main usages of loops is to process strings.
• Examples:
– Count the occurrence of one or more characters in a string
– Verify that the contents of a string meet a criteria
• All of this requires basic string processing algorithms
3. 4 String Processing Methods
• variable.isupper
– Test to see if current character is upper case
– Returns True or False
• variable.islower
– Test to see if current character is lower case
– Returns True or False
• variable.upper
– Converts current character to upper case
• variable.lower
– Converts current character to lower case
4. Counting Matches
• We often want to count the
number of values that meet
a given condition.
• Example: count the number
of upper case characters in
a string
uppercase = 0
for char in string :
if char.isupper() :
uppercase =
uppercase + 1
• Sometimes, you need to count
the number of occurrences of
multiple characters
within a string.
• Example, suppose we would like
to know how many vowels are
contained in a word.
vowels = 0
for char in word :
if char.lower() in "aeiou" :
vowels = vowels + 1
a & b
Note: using “.lower” allows us to limit the
number of characters that must be specified
in the literal string
5. Finding All Matches
• You may need to find the position of each match within a string. For example,
suppose you are asked to print the position of each uppercase letter in a sentence.
• You cannot use the for statement that iterates over all characters because you
need to know the positions of the matches. Instead, iterate over the positions
(using for with range) and look up the character at each position:
sentence = input("Enter a sentence: ")
for i in range(len(sentence)) :
if sentence[i].isupper() :
print(i)
6. What We Covered Today
1. Tables
1. Creating
2. Accessing
3. Neighbors
4. Summing
2. List Algorithms
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
7. What We’ll Be Covering Next Time
1. Lists, List algorithms
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/
Editor's Notes
New name for the class
I know what this means
Technical professionals are who get hired
This means much more than just having a narrow vertical knowledge of some subject area.
It means that you know how to produce an outcome that I value.
I’m willing to pay you to do that.