9.10. SummaryΒΆ

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: 'This'[2] evaluates to 'i'.

length function (len)

Returns the number of characters in a string. Example: len('happy') evaluates to 5.

for loop traversal (for)

Traversing a string means accessing each character in the string, one at a time. For example, the following for loop:

s: str
s = 'Example'
for i in range(0, len(s), 1):
    print(s[i])

executes the body of the loop 7 times with different values of i each time.

string comparison (>, <, >=, <=, ==, !=)

The six common comparision operators work with strings, evaluating according to lexigraphical order. Examples: 'apple' < 'banana' evaluates to True. 'Zeta' < 'Appricot' evaluates to False. 'Zebra' <= 'aardvark' evaluates to True because all upper case letters precede lower case letters.

You have attempted of activities on this page
9.9. Characters"> 9.11. Glossary">Next Section - 9.11. Glossary