Home > Backend Development > Python Tutorial > How python function returns multiple values

How python function returns multiple values

PHPz
Release: 2023-05-22 13:19:06
forward
1852 people have browsed it

Generally, a function has only one return value, and the same is true for Python. However, the Python function can save the returned multiple values ​​into a sequence by returning a list or tuple, thereby indirectly achieving the purpose of returning multiple values. .

Instructions

1. Store the multiple values ​​to be returned in a list or tuple in advance, and then the function returns the list or tuple.

2. The function directly returns multiple values, separated by commas. Python will automatically encapsulate multiple values ​​into a tuple, and its return value is still a tuple.

Examples

def multi_return():
    return_tuple = ('张三', 12)
    return return_tuple
def multi_return2():
    return '张三', 12
print(multi_return())
result = multi_return2()
print('multi_return2返回值是=,类型是=', result, type(result))
Copy after login

What are the main application areas of python

1. Cloud computing, typical application OpenStack.

2. WEB front-end development, many large websites are developed in Python.

3. Artificial intelligence applications. Artificial intelligence developed based on big data analysis and deep learning is essentially unable to leave python.

4. For system operation and maintenance engineering projects, the standard configuration for automated operation and maintenance is python Django/flask.

5. Financial management analysis, quantitative trading, financial analysis.

6. Big data analysis.

The above is the detailed content of How python function returns multiple values. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template