[Tutor] tutorial

Boudewijn Rempt boud@valdyas.org
Wed, 23 Jan 2002 15:13:18 +0100 (CET)


On Wed, 23 Jan 2002 AMoore4437@aol.com wrote:

> >>> print "Here are the ten numbers from 0 to 9"
> Here are the ten numbers from 0 to 9
> >>> for 1 in range(10):
>     print 1,
>
> SyntaxError: can't assign to literal
>

The range command produces a series of numbers, and tries to assign them
to the variable following the keyword 'for'. It has to be a variable,
because you can't assign something to anything that can't change --
like 1. 1 will always be 1, and you can never change it, and neither can
'range'. Now if you use _i_ instead of _1_, you'll have created a variable
that can take any value, including the numbers 0 to 9.

Boudewijn Rempt  | http://www.valdyas.org