List Info

Thread: range() help




range() help
country flaguser name
United States
2007-04-17 06:42:50
Alright I'm a bit confused when looking at how range works. 
I'm reading
lesson 4.3 in the python tutorial. http://docs.pyt
hon.org/tut/node6.html

I came across this:

>>> range(-10, -100, -30)
[-10, -40, -70]

How come it prints on -40 or -70.

Does -70 come from -70 -> -100?

This is really confusing me.
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: range() help
country flaguser name
Turkey
2007-04-17 06:55:30
On Tuesday 17 April 2007 14:42:50 pythonuni-code.com wrote:
> >>> range(-10, -100, -30)
>
> [-10, -40, -70]
>
> How come it prints on -40 or -70.
>
> Does -70 come from -70 -> -100?
>
from -10 to -100 (excluding -100)
-10-30 = -40
-40-30= -70
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: range() help
country flaguser name
Sweden
2007-04-17 06:57:18
Reply to pythonuni-code.com 07-04-17 07:42:

>How come it prints on -40 or -70.
>
>Does -70 come from -70 -> -100?
>
>This is really confusing me.

I don't really understand your question, the definition of
range

range(...)
     range([start,] stop[, step]) -> list of integers

     Return a list containing an arithmetic progression of
integers.
     range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!)

defaults to 0.
     When step is given, it specifies the increment (or
decrement).
     For example, range(4) returns [0, 1, 2, 3].  The end
point 
is omitted!
     These are exactly the valid indices for a list of 4
elements.

So you are basically telling python to start from -10, and
then 
subtract -30 until it reaches -100.
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )