This article mainly introduces the return values of Python functions. examples show how to return a return value and multiple return values in Python. For more information, see the following example. 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.
Def firstvalue (a, B): c = a + B return cprint 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:
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.