THE PYTHON RANGE() FUNCTION
In this section, we discuss the range() function that you can use to iterate through a list, as shown here:
>>> for i in range(0,5):
...   print i
...
0
1
2
3
4
You can use a for loop to iterate through a list of strings, as shown here:
>>> x
['a', 'b', 'c']
>>> for w in x:
...   print w
...
a
b
c
You can use a for loop to iterate through a list of strings and provide additional details, as shown here:
>>> x
['a', 'b', 'c']
>>> for w in x:
...   print len(w), w
...
1 a
1 b
1 c
The preceding output displays the length of each word in the list x, followed by the word itself.
Counting Digits, Uppercase, and Lowercase Letters
Listing 3.3 shows the content of the Python script CountCharTypes.py that counts the occurrences of digits and letters in a string.
Listing 3.3: Counter1.py
str1 = "abc4234AFde"
...