Python function return value instance analysis

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.