Introduction to Python functions 2. Introduction to python Functions

Source: Internet
Author: User

Introduction to Python functions 2. Introduction to python Functions

1. When a function has multiple return values, multiple return values will appear in the form of tuples.

Def test1 (): print ("in the test1") return 'end' def test2 (): print ("in the test2") def test3 (): print ("in the test3") return 1, 'Hello', ['frank', 'lile'], {'name ': 'frank'} # returns a tuples x = test1 () y = test2 () z = test3 () print (x) print (y) print (z) # result in the test1in the test2in the test3endNone (1, 'Hello', ['frank', 'Lee '], {'name': 'frank'}) # tuples

2. Parameter Function call --- location call, keyword call

Def test (x, y): print (x) print (y) test () # Call print ("------------ I am a split line ------------") test (y = 2, x = 1) # keyword call # result: 12 ------------ I am a split line ------------ 12

3. The real parameter will overwrite the form parameter

Def test (x, y = 2): print (x, y) test (1) test (1, 3) # result 1 21 3

4. When the number of real parameters is less than the parameter value, the default parameter value is used.

Def conn (host, port = 3306): print (host, port, sep = ':') conn ("mysql-test") # result mysql-test: 3306

 

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.