Transcription of Basic Python Programming: for loops and reading files
{{id}} {{{paragraph}}}
DRAFT March, 2004 Ron Zacharski 3 Basic Python programming : for loops and reading files In the last tutorial we covered a range of topics including lists and how to define your own functions. In this tutorial we will continue this whirlwind introduction to Python and cover what are called for loops and also learn how to read information from files . The next tutorial, Tutorial 4, will be our easy day' a breather. In that tutorial we will go through a set of exercises that will allow you to practice and apply what you've learned. For loops Frequently we would like to perform the same actions on each element in a list that is we would like to iterate through a list performing a sequence of commands. To do this we use the for' statement, which has the following format: for name in List: command1.
C:\AI\python\sample.txt In Chapter 1 we noted that the backslash character ‘\’ has special meaning in Python strings—namely that the next character should be interpreted in some special way. In order to get actual backslashes in a Python string we need to put a backslash before each of them. For example: filename = 'C:\\AI\\python\\sample ...
Domain:
Source:
Link to this page:
Please notify us if you found a problem with this document:
{{id}} {{{paragraph}}}