A colon

• An indented statement

In a for block, Python gives the name to each element in the iterable, one at a time, in order. It reuses the name each time through the loop. After Python gives the name to a new element, it executes the instructions in the code block.

The example at the beginning of this section computes and prints the ASCII value of each character in a string (using the ord() function):

the

ascii

value

of

h

is

104

the

ascii

value

of

e

is

101

the

ascii

value

of

l

is

108

the

ascii

value

of

l

is

108

the

ascii

value

of

o

is

111

the

ascii

value

of

!

is

33

Was this article helpful?

0 0

Post a comment