Print is a string that shows the user what is going on inside the computer. Print is a string that shows the user what is going on inside the computer. The computer cannot use the contents of print, and return is the return value of the function. This value is usually invisible to human users, but computers can use it for other functions.

Print does not affect the function in any way. It’s just to help humans use functions. It is useful for understanding how a program works, and can be used during debugging to check various values in a program without breaking the program. Print does nothing but help humans see what they want to see.

Return is the primary way a function returns a value. All functions return a value, which returns None if there is no return statement. The value returned by a function can be further passed as a parameter to another function, stored as a variable, or simply printed for human use. Return is intended to immediately interrupt the control flow and exit the current function, returning the specified value to the caller who called the function.

Examples of application

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()

The result is:

HELLO

this is None

that is RETURN

An analogy

In common terms:

Print shows you what you want.

Return is to send you the result you want.

It’s like

You want to check the balance of your bank card, you check by SMS, you will see the SMS reminder of the balance — ending with *** the balance is 3000 yuan. This text message is equivalent to the function of Print.

When you want to buy a 3000 yuan mobile phone, you go to the mobile phone store to show the attendant a message, said that he has 3000 yuan, to take away the phone, the result is directly thrown out. This time need is to take out the bank card, although you can not see the money in the bank card, but it can be used for you. This is equivalent to the return function.

Let’s look at return and print in Python

Print: Print: print: print: print: print: print: print: print: print: print: print: print: print: print

The purpose of print is relatively easy to understand

print (1)

print (‘asdfghj’)

The output

1

asdfghj

Above is output data to the control end

One of the functions of return is to return the computed value

No return statement

x = 1

y = 2

def add (x, y):

z = x + y

print (add(x,y))

The output

None

There is no return statement, so there is no assignment to add(), which prints out as null (None).

A return statement

x = 1

y = 2

def add (x, y):

z = x + y

return z

print (add(x,y))

The output

3

Note: The return value can only be displayed by print, but print is not required in interactive mode

def func1():

for i in range(1, 5):

return (i)

print (func1())

print (“……” )

func1()

The output

1

.

As above, a direct call to func1() gives no output.