Home > Article > Backend Development > What is the usage of python return
Python return usage: 1. Return the return value of the function; 2. Terminate the running of the program and exit early. For example, when an error occurs in the function, use return to terminate the running of the function.
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer. This method is suitable for all brands of computers.
python return usage:
(1), return the return value of the function
(2), terminate the running of the program, and exit early.( For example: when an error occurs within a function, use return to terminate the function)
def testReturn(x): if x > 10000: return print "test return!!" #这句话永远不会得到执行 elif x > 1000: return 100 elif x > 100: return 10 elif x > 10: return 1 else: return 0 print testReturn(9999999) #result = None print testReturn(9999) #return = 100 print testReturn(999) #return = 10 print testReturn(99) #return = 1 print testReturn(9) #return = 0
Related free learning recommendations: python video tutorial
The above is the detailed content of What is the usage of python return. For more information, please follow other related articles on the PHP Chinese website!