Python function return value instance analysis
This example describes how to use the function return value of Python. Share it with you for your reference. The specific analysis is as follows:
Recently, I learned some basic usage of Python. When I saw the definition function, I found that I could only return one returned value. It is convenient to return multiple returned values in matlab. I checked it online, we can see that there are methods to return multiple values.
Python functions return values in two forms:
1. Return a value.
2. Multiple values are returned.
Now let's take a look at the returned value.
?
1 2 3 4 |
Def firstvalue (a, B ): C = a + B Return c Print firstvalue (1, 2) # result: 3 |
Let's look at the returned values: how can we return multiple values? If a function is called in other languages, only one value can be returned. Maybe I am not familiar with all languages, I know that only one value can be returned in a language, while python can return multiple values, which is very convenient. Let's check the Code:
?
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 Python programming.