The "loop and a half"
Steve D'Aprano
steve+python at pearwood.info
Wed Oct 4 22:20:08 EDT 2017
More information about the Python-list mailing list
Wed Oct 4 22:20:08 EDT 2017
- Previous message (by thread): The "loop and a half"
- Next message (by thread): The "loop and a half"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 5 Oct 2017 09:42 am, Stefan Ram wrote: > Steve D'Aprano <steve+python at pearwood.info> writes: >>>So, "bottom-up" in this case means: iterators should be >>>taught before for-loops. >>Why? > > The syntax for is (from memory): > > for <variable> in <expression>: <suite> > > . As an example, I might show: > > for i in range( 3 ): ... > > . This raises the question: > > "What is the value of »range( 3 )«?". That's easy: in Python 2, it is a list [0, 1, 2]. In Python 3, it is a range object, a lazily calculated list-like object. > "Bottom up" means that the simple and constituent parts > are taught before the complex and compound parts. I.e., > »range( 3 )« is explained before »for i in range( 3 ):«. This is reductionist thinking. Which is sometimes useful, but not here. If you were teaching people to drive a car, would you insist on teaching them how to pull out and rebuild the engine before sitting them in the drivers seat? If you were teaching people to swim, would you teach them the laws of hydrodynamics and the chemistry of water before going near a swimming pool? If you were teaching people to ride a horse, would you start by having them dissect a dead horse and learn the biomechanics of the horse skeletal and muscular systems? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse.
- Previous message (by thread): The "loop and a half"
- Next message (by thread): The "loop and a half"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list