Python Basics-Function Chapter

Source: Internet
Author: User

1 #any number of arguments (optional)2 defTest (a,*b):3     returnA, b4 5 Print(Test (1,2,3,4,5))6 #a tuple is returned7 8 #any number of keyword arguments9 defTest (a,**b):Ten     returnA, b One  A Print(Test (a=1,c=2,d=3,e=4,f=5)) - #The return is a dictionary -  the #make an argument optional - #to specify a default value for an argument, an empty string allows the argument to become optional - defTest (a="',**b): -     returnA, b +  - Print(Test (c=2,d=3,e=4,f=5)) +  A #The return value, which can be a dictionary, a list, a tuple, an aggregate function.  at #returns a function - deftest_2 (): -     Print('world!') - deftest_1 (): -     Print('Hello') -     returntest_2 () in  - test_1 () to #Returns a collection + deftest_3 (): -A = [1,1,2,2,3,4,5] the     returnset (a) *  $ Print(Test_3 ())Panax Notoginseng  - #Import function Various writing and explanation: the  + #Import Module_name # Importing the entire module A #From module_name import function_name # Specific functions in the Import module the #From module_name import function_name as FN # Use as to assign aliases to functions + #Import module_name as MN # Use as to assign aliases to modules - #From module_name Import * # Imports all functions in the module $  $  - #Order of function arguments: - #function Parameters: Required parameter, default parameter, optional parameter, keyword parameter the defTest_4 (a,b=1,*c,**d): -     returna,b,c,dWuyi  the Print(Test_4 (1,2,3,4,f=5))

Python Basics-Function Chapter

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.