What is the difference between 'print' and 'return' statements in Python function definitions? In what order should they be written?


Replace this line with your code.


Print, prints to the console, return doesn't.
Inside a function, return gives a new value, like mathematical functions, you give an x and get a y. Now, if you call a function in any point of your code there are usually two ways to do it. Either like "function(argument)" or "print function(argument)".
Inside the function, your ending value will be given either using "return" or sometimes "print". If you want the final result to be printed, you can either call "print function(argument)" or "function(argument", but you can only do the second, if you have the print already in the function.
It's better to use return though, because you don't usually print function result in more complex programs, or when you use it in an if statement. Hope this helps...


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.