[Edu-sig] Overloading (was Re: more on "variable names")

Laura Creighton lac at openend.se
Wed May 27 11:28:35 CEST 2009


p.s.

Here is a test to see if your students understand about binding, or if
they are walking around with it confused with equality.

>>> class Animal:
...     def __init__(eyecolour, sound, action):
...             self.eyecolour = eyecolour
...             self.sound = sound
...             self.action = action
...
>>> cat = Animal('green', 'miaux', 'pounce')
>>> dog = Animal('brown', 'woof', 'wag')
>>> vlerb = Animal('green', 'miaux', 'pounce')


Now go ask them if what they think

vlerb == cat

will print.

This is an easier place to clear up the misunderstanding than the first
time they start passing mutable objects as defaults to a function or a
method, which is where my classes in the past have tended to blow up
with this sort of misunderstanding.

Laura


More information about the Edu-sig mailing list