Section 7.22 Summary
This chapter introduced a lot of new ideas. The following summary may prove helpful in remembering what you learned.
Glossary Glossary
- indexing (
[]
). - Access a single character in a string using its position (starting from 0). Example:
'This'[2]
evaluates to'i'
. - length function (
len
). - Returns the number of characters in a string. Example:
len('happy')
evaluates to5
. - for loop traversal (
for
). - Traversing a string means accessing each character in the string, one at a time. For example, the following for loop:
for ch in 'Example': ...
executes the body of the loop 7 times with different values ofch
each time. - slicing (
[:]
). - A slice is a substring of a string. Example:
'bananas and yogurt'[3:6]
evaluates toana
(so does'bananas and yogurt'[1:4]
). - string comparison (
>, <, >=, <=, ==, !=
). - The six common comparision operators work with strings, evaluating according to lexigraphical order 1 . Examples:
'apple' < 'banana'
evaluates toTrue
.'Zeta' < 'Appricot'
evaluates toFalse
.'Zebra' <= 'aardvark'
evaluates toTrue
because all upper case letters precede lower case letters. - in and not in operator (
in
,not in
). - The
in
operator tests whether one string is contained inside another string. Examples:'heck' in "I'll be checking for you."
evaluates toTrue
.'cheese' in "I'll be checking for you."
evaluates toFalse
.
http://en.wikipedia.org/wiki/Lexicographic_order