Python is going to be hard

Rob Gaddi rgaddi at technologyhighland.invalid
Wed Sep 3 15:01:18 EDT 2014


On Wed, 03 Sep 2014 11:55:13 -0700
Ethan Furman <ethan at stoneleaf.us> wrote:

> On 09/03/2014 11:49 AM, Seymore4Head wrote:
> > 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
> >
> > Ok, I understand now that x is actually the first item in the list.
> > What I want is a loop that goes from 1 to the total number of items in
> > the list steve.
> 
> No, you don't understand yet.
> 
> The /first/ time through the loop 'x' is the first item in the list.
> 
> The /second/ time through the loop 'x' is the second item in the list.
> 
> The /third/ time through the loop 'x' is the third item in the list.
> 
> . . .
> 
> Keep persisting!
> 
> --
> ~Ethan~

Python 'for' is better read as 'for each'.

-- 
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