[Edu-sig] What version of Python to teach ....
Gregor Lingl
gregor.lingl at aon.at
Sun Apr 19 23:48:00 CEST 2009
Edward Cherlin schrieb:
> On Sun, Apr 19, 2009 at 12:07 PM, Laura Creighton <lac at openend.se> wrote:
>> One note:
>> It is very important to teach your students how to read code. ...
...
>>
>> It would be interesting to go through this collection of examples
>> used in teaching 2.x, and find out how much of the new code just
>> works, and what are the remaining issues
It's certainly not the only issue, if code 'just works' or not. There
are quite a few
differences between Python 2 and Python 3 that concern the semantics of
code.
As a very elementary example consider the different meaning of
range(5)
in Python 2/3. Imho in this case at first it would be important to find
didactically clean ways to explain new concepts like these to beginners.
Of course I know that these concepts are not entirely new, but with
Python 3 they need to appear at a much earlier stage, e. g. when
introducing the for loop.
In 'former times' we could say: range(5) is a list (i. e. a container or
a compound
data type) and the for loop does things for every element in this list.
And you could view
this list:
>>> range(5)
[0, 1, 2, 3, 4]
>>> for item in range(5):
print item
0
1
2
3
4
>>> type(range(5))
<type 'list'>
... easily to grasp
Now, with Python 3, we have:
>>> range(5)
range(0, 5)
>>> for item in range(5):
print(item)
0
1
2
3
4
>>> type(range(5))
<class 'range'>
How do you explain the nature of range to beginners? (Not a a rhetorical
question, I'd really like to know different approaches how to do it!)
At least you can see, that this is a much more important question
than e. g. the parentheses around item (because of print being a
function now - but even here the semantic difference between a
function and a statement is the point and not the parentheses ...)
Regards,
Gregor
More information about the Edu-sig
mailing list