Python is going to be hard

Rob Gaddi rgaddi at technologyhighland.invalid
Wed Sep 3 14:19:04 EDT 2014


On Wed, 03 Sep 2014 14:10:42 -0400
Seymore4Head <Seymore4Head at Hotmail.invalid> wrote:

> import math
> import random
> import sys
> b=[]
> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
> for x in steve:
>     print (steve[x])
> 
> Traceback (most recent call last):
>   File "C:\Functions\blank.py", line 7, in <module>
>     print (steve[x])
> IndexError: list index out of range

You're failing to go through the basic tutorials, and blaming the
language when you don't understand things.

'for x in steve' does not sweep x over the indices of steve.  'for x in
steve' sweeps x over the sequential _values_ in steve.  This would have
been clear if you were to add a print(x) into the loop.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list