The difference between print and return in python

(*-*)浩
Release: 2019-07-23 14:17:21
Original
4819 people have browsed it

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.

The difference between print and return in python

#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()
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template