[Edu-sig] teaching Python

Mark Engelberg mark.engelberg at alumni.rice.edu
Fri Apr 23 21:24:15 CEST 2010


On Fri, Apr 23, 2010 at 11:46 AM, Bill Punch <punch at cse.msu.edu> wrote:
> To round out the
> top three, which are the ones that get even my best students, look at the
> below:
>
> myVar = 27
>
> def myFun ():
>     print myVar
>     myVar += 1
>     return myVar
>
> print myFun
>
> What happens when you run this?
>

To fully appreciate Bill's example, I think it's worth pointing out
that this version would behave exactly as expected:

myVar = 27

def myFun ():
    print myVar
#    myVar += 1
    return myVar

print myFun()


More information about the Edu-sig mailing list