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