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