Game Development Reference
In-Depth Information
>>> for i in range([0, 1, 2, 3, 4, 5, 6, 7, 8,
9]):
... print(i)
...
0
1
2
3
4
5
6
7
8
9
>>>
Try typing this into the shell: for thing in ['cats', 'pasta',
'programming', 'spam']: and press Enter, then type print('I really like
' + thing) and press Enter, and then press Enter again to tell the shell to end the for-
block. The output should look like this:
>>> for thing in ['cats', 'pasta', 'programming',
'spam']:
... print('I really like ' + thing)
...
I really like cats
I really like pasta
I really like programming
I really like spam
>>
And remember, because strings are also a sequence data type just like lists, you can use
them in for statements as well. This example uses a single character from the string on
each iteration:
>>> for i in 'Hello world!':
... print(i)
...
H
e
l
l
Search WWH ::




Custom Search