[Edu-sig] Interactive interpreter: expressions vs. statements

Ka-Ping Yee python-edu@zesty.ca
Sat, 15 Feb 2003 01:54:54 -0600 (CST)


Hello all.

I'm teaching a course in Python this semester at UC Berkeley.
It's the first time i've designed and taught a course on my own,
so it's an interesting challenge.  You can check it out at
http://zesty.ca/bc/.  If you promise not to submit any forms,
you can log in with the username and password "guest".

Okay, on to the main topic.

There are two related problems for Python beginners that i seem
to be encountering over and over again:

    1.  Confusion about expressions vs. statements.

        The interpreter appears to yield the same response to
        "1 + 1" and to "print 2".  But the "2" you see comes
        from different sources: for "1 + 1" it's the interpreter
        displaying the result, and for "print 2" it's the print
        statement sending the result to the terminal.

    2.  Confusion about return vs. print.

        If you define a function that returns 3 and a function
        that prints 3, they appear to evaluate to the same thing.
        The function that prints 3 actually returns None, but you
        can't see that because the interpreter chooses not to
        display the result when it is None.

I talked to Michael Clancy recently, in the Berkeley CS department.
He reports similar experiences in his 10+ years of teaching Scheme:
once the students know a "print" command, lots of them will run into
trouble with issue #1.  This seems to happen consistently, year
after year.

I'd like to know whether any of you have encountered these
problems before, how frequently they turn up, and how you have
dealt with them.

Thanks!

(I have an idea in mind, but i'd like to hear about your
experiences first.)


-- ?!ng