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