Home  >  Article  >  Backend Development  >  How python function returns multiple values

How python function returns multiple values

PHPz
PHPzforward
2023-05-22 13:19:061809browse

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))

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete