On 14 May 2013 17:11, Marc Tompkins <[email protected]> wrote:
>
> The OP expressed some confusion between what a function DOES and what it
> RETURNS. It occurs to me that the print() function (or, more generically,
> ANY print() function - it doesn't have to be Python 3) is a good
> demonstration.
>
> Our first exposure to print() is very simple: display something on the screen
> - what could possibly go wrong? However, print() can redirect its output to
> files, printers, skywriters, etc. - and sometimes it will be a real question
> whether print() succeeded in producing any output. (If your program is
> trying to write data into a file, you'd probably like to know whether it
> worked or not.) So print() - like all functions - has an optional return
> value, which your program can read to see whether it needs to retry, display
> an error message, etc.
>
> Again, the return value of print() - e.g. success/failure - is separate from
> what print() actually prints.
I was surprised by this so I've just tested it and checked the docs;
the print() function does not return anything (i.e. it returns None).
>>> a = print('qwe')
qwe
>>> a
>>> print(a)
None
http://docs.python.org/3/library/functions.html#print
Oscar
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor