Home > Article > Backend Development > The difference between print and return in python
print is just to display a string to the user that represents what is going on inside the computer. The computer cannot use the content of the print.
#return is the return value of the function. This value is usually invisible to human users, but computers can use it in other functions.
#print does not affect the function in any way. It's just to help humans use functions. (Recommended learning: Python Video Tutorial)
It is very useful for understanding how the program works, and can be used in debugging to check various values in the program without interrupting the program. Print does nothing but help humans see the results they want to see.
return is the main way for functions to return values. All functions will return a value, if there is no return statement it will return None. The value returned by a function can be further passed as a parameter to another function, stored as a variable, or simply printed for consumption by human users. return is intended to immediately interrupt the flow of control and exit the current function, returning the specified value to the caller of the calling function.
Application Example
def print_hello(): x = "HELLO" print(x) def print_return(): x = "RETURN" return x def main(): Hello = print_hello() Return = print_return() print("this is %s " % Hello) print("that is %s " % Return) if __name__ == "__main__": main()
print is to show you the results you want.
return is to send you the result you want.
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of The difference between print and return in python. For more information, please follow other related articles on the PHP Chinese website!