Example analysis of a Python function return value

Source: Internet
Author: User

This example describes the use of Python's function return value. Share to everyone for your reference. The specific analysis is as follows:

Recently learned some basic use of Python, see the definition function, found that it seems only return a return value, think of Matlab return a number of return values more convenient Ah, online check, see there is a way to return multiple values.

There are two forms of the Python function return value:

1 returns a value.

2 returns multiple values.

Now look at the return of a value of the bar.

?

1 2 3 4 def firstvalue (a,b): c = a + B return c print firstvalue (1,2) #结果: 3

And look at the return of multiple values: How can you return multiple values, other languages generally call the function, you can only return a value, maybe I am not familiar with all the languages, I know that the language can only return a value, and Python can return multiple values, feel very convenient, send a code look at:

?

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 your Python programming.

Related Article

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.