On Tue, May 14, 2013 at 1:51 AM, Alan Gauld <alan.ga...@btinternet.com>wrote:
> On 14/05/13 00:01, Daniel Magruder wrote: > > I am still confused as what return does. >> > > This isn't a direct response to Alan, but to something the OP expressed many, many messages ago... 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. In general, all functions can have effects - like the output of print() - and/or return something. Sometimes you're interested in one and not the other; for instance, most of the time you don't care about print()'s return value. On the other hand, there's a style of programming called "functional", in which everything is a function and NOTHING has any side effects at all - I must confess, I find it hard to get my head around that.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor