This example describes the use of Python's function return value. Share to everyone for your reference. The specific analysis is as follows:
Recently learned some basic use of Python, see the definition function, found that it seems only return a return value, think of Matlab return a number of return values more convenient Ah, online check, see there is a way to return multiple values.
There are two forms of the Python function return value:
1 returns a value.
2 returns multiple values.
Now look at the return of a value of the bar.
?
1 2 3 4 |
def firstvalue (a,b): c = a + B return c print firstvalue (1,2) #结果: 3 |
And look at the return of multiple values: How can you return multiple values, other languages generally call the function, you can only return a value, maybe I am not familiar with all the languages, I know that the language can only return a value, and Python can return multiple values, feel very convenient, send a code look at:
?
1 2 3 4 5 |
def secondvalue (a,b): c = a + B return (a,b,c) x,y,z = secondvalue (1,2) print ' x: ', X, ' y: ', y, ' z: ', Z |
I hope this article will help you with your Python programming.