Re: Teaching the "range" function in Python 3

2017-07-02 Thread Rick Johnson
On Saturday, July 1, 2017 at 12:48:39 AM UTC-5, Christian Gollwitzer wrote: > Am 30.06.17 um 04:33 schrieb Rick Johnson: > > And to further drive home the point, you can manually > > insert a list literal to prove this: > > > > >>> range(10) > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > >>

Re: Teaching the "range" function in Python 3

2017-07-02 Thread Rick Johnson
On Thursday, June 29, 2017 at 9:58:23 PM UTC-5, Chris Angelico wrote: > On Fri, Jun 30, 2017 at 12:33 PM, Rick Johnson > > A better *FIRST* example would be something like this: > > > > def add(x, y): > > return x + y > > > > When teaching a student about functions, the first step is >

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Christian Gollwitzer
Am 30.06.17 um 04:33 schrieb Rick Johnson: And to further drive home the point, you can manually insert a list literal to prove this: >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> for value in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: ... print(value) ... 0 1 No

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Chris Angelico
On Sat, Jul 1, 2017 at 1:25 PM, MRAB wrote: > On 2017-07-01 03:12, Stefan Ram wrote: >> >> Terry Reedy writes: >>> >>> range is a class, not a function in the strict sense. >> >> >>»the built-in function range() returns an iterator of integers« >> >> The Python Language Reference, Re

Re: Teaching the "range" function in Python 3

2017-06-30 Thread MRAB
On 2017-07-01 03:12, Stefan Ram wrote: Terry Reedy writes: range is a class, not a function in the strict sense. »the built-in function range() returns an iterator of integers« The Python Language Reference, Release 3.6.0, 8.3 The for statement Python 3.6.1 (v3.6.1:69c0db5, Mar

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Terry Reedy
On 6/30/2017 1:07 PM, Irv Kalb wrote: Thanks to everyone who responded to my question about teaching the range function. range is a class, not a function in the strict sense. Classes represent concepts. Instances of classes represent instances of the concept. Range represent the concept 'a

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Irv Kalb
> On Jun 29, 2017, at 2:21 PM, Chris Angelico wrote: > > On Fri, Jun 30, 2017 at 6:57 AM, Irv Kalb wrote: >> I am wondering if other teachers have run into this. Is this a real >> problem? If so, is there any other way of explaining the concept without >> getting into the underlying details

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Chris Angelico
On Sat, Jul 1, 2017 at 2:17 AM, Stefan Ram wrote: > However, to my defense, I must say that in this post my intend > was to demonstrate what is happening /behind the curtains/ when > the »for« loop is running, so in this special case, it might be > appropriate to use a function that otherw

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Steve D'Aprano
On Fri, 30 Jun 2017 09:17 am, Stefan Ram wrote: b = a.__iter__() Don't do that. Dunder ("Double UNDERscore") methods like __iter__ should only be called by the Python interpreter, not by the programmer. The right way to create an iterator is to call the built-in function iter: b = iter(a)

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Steve D'Aprano
Hello Irv, and welcome! Good to have a teacher of Python here! On Fri, 30 Jun 2017 06:57 am, Irv Kalb wrote: [...] > Now I am looking at the change in the range function. I completely understand > the differences between, and the reasons for, how range works differently in > Python 2 vs Python

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Peter Otten
Gregory Ewing wrote: > Don't start with range(). Start with lists, and introduce the for > loop as a way to iterate over lists. Leave range() until much later. > You should be able to go a *long* way without it -- it's quite > rare to need to iterate over a range of ints in idiomatic Python > code

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Rustom Mody
On Friday, June 30, 2017 at 8:28:23 AM UTC+5:30, Chris Angelico wrote: > On Fri, Jun 30, 2017 at 12:33 PM, Rick Johnson wrote: > > A better *FIRST* example would be > > something like this: > > > > def add(x, y): > > return x + y > > > > When teaching a student about functions, the firs

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Chris Angelico
On Fri, Jun 30, 2017 at 12:33 PM, Rick Johnson wrote: > A better *FIRST* example would be > something like this: > > def add(x, y): > return x + y > > When teaching a student about functions, the first step is > to help them understand *WHY* they need to use functions, > and the second

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Rick Johnson
On Thursday, June 29, 2017 at 4:01:07 PM UTC-5, Irv Kalb wrote: > > [...] > > But Python 3's version of the range function has been > turned into a generator. Again, I understand why this > happened, and I agree that this is a good change. The > problem is, how can I explain this concept to stude

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Gregory Ewing
Irv Kalb wrote: In Python 2, I easily demonstrated the range function using a simple print statement: print range(0, 10) I discussed how range returns a list. I gave many examples of different values being passed into range, and printing the resulting lists. Next, I introduced the concept of

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Cameron Simpson
On 29Jun2017 13:57, Irv Kalb wrote: Now I am looking at the change in the range function. I completely understand the differences between, and the reasons for, how range works differently in Python 2 vs Python 3. The problem that I've run into has to do with how to explain what range does in

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Ian Kelly
On Thu, Jun 29, 2017 at 2:57 PM, Irv Kalb wrote: > Now I am looking at the change in the range function. I completely > understand the differences between, and the reasons for, how range works > differently in Python 2 vs Python 3. The problem that I've run into has to > do with how to explai

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Chris Angelico
On Fri, Jun 30, 2017 at 6:57 AM, Irv Kalb wrote: > I am wondering if other teachers have run into this. Is this a real problem? > If so, is there any other way of explaining the concept without getting into > the underlying details of how a generator works? Do you think it would be > helpful