Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 25 Online
OpenStudy (anonymous):

Hi everyone, on the lecture 4 handout in the second block of code where Eric introduces the keywords 'def' and 'return' for the creation of a function, i've rewritten the code with the keyword 'print' where 'return' was used and obtained the same result. I'm not sure I fully grasp the use of the 'return' keyword. And the line 'return None' seems to change nothing in the result as well. Any thoughts would help. Thanks!

OpenStudy (anonymous):

If you are only using one function at a time, printing the result and simply returning it will be the same. However, suppose you want to combine several functions. Then you need some way of storing and referring to the output of each function. That is what "return" enables you to do--it stores the output of the function so that it can be used later.

OpenStudy (anonymous):

I thought it would be 'local' and hence not be affected by other functions in the code. I guess it will become clearer later. Thanks for your input! Cheers

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!