question about input() and/or raw_input()

Chris Angelico rosuav at gmail.com
Sat Jan 18 23:59:58 EST 2014


On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> Because these two pieces of code
>
>>>> def foo(x): print x+1
>
>>>> def bar(x): return x+1
>
> look identical (to a beginner at least)
>
>>>> foo(3)
> 4
>>>> bar(3)
> 4
>>>>

As do these pieces of code:

>>> def quux(x): return str(x+1)
>>> def quux(x): return hex(x+1)[2:]

But we don't decry hex or str because of it. Every function has its
use and purpose. If someone uses the wrong tool for the job, s/he will
have to figure that out at some point - it doesn't mean the tool is
wrong.

If you're not using the REPL, print is critical. Don't assume everyone
uses interactive mode.

ChrisA



More information about the Python-list mailing list