Other Forms 1:
1. Defining functions
Def test4 (a = ()):
Print (' ############### #test4 ################ ')
Print (Type (a))
Print (a)
2. Calling functions
Call correctly:
Test4 ((1, 2)) #a在函数体内部为tuple类型
Test4 (a= (1, 2)) #a在函数体内部为tuple类型
Test4 (1,)) #a在函数体内部为tuple类型
Test4 (a= (1,)) #a在函数体内部为tuple类型
Test4 ((1)) #a在函数体内部为int类型, non-tuple type
Test4 (a= (1)) #a在函数体内部为int类型, non-tuple type
TEST4 (1) #a在函数体内部为int类型, non-tuple type
Test4 (a=1) #a在函数体内部为int类型, non-tuple type
Error Call:
Test4 (1, 2) #TypeError: Test4 () takes at the most 1 argument (2 given)
Test4 (1, b=2) #TypeError: Test4 () got an unexpected keyword argument ' b '
Test4 (A=1, b=2) #TypeError: Test4 () got an unexpected keyword argument ' b '
- 5
Other Forms 2:
1, define functions
Def test5 (b = {}):
print (' ############### #test5 ################ ')
Print (type (b))
print (b)
2, call function
correct invocation:
Test5 ({ ' A ': 2}) #b在函数体内部为dict类型
Test5 (b={' a ': 2})
Test5 ({' A ': 2, ' B ': 3}) #b在函数体内部为dict类型
Test5 (b={' a ': 2, ' B ': 3})
Test5 (b=2) #b在函数体内部为int类型, non-dict type
Error Invocation:
Test5 (A=1, b=2) #TypeError: Test5 () got an unexpected keyword argument ' a '
Test5 (1, 2) #TypeError: Test5 () takes at the most 1 argument (2 given)
Test5 (1, b=2) #TypeError: test5 () got multiple values for keyword argument ' b '
- 6
Other Forms 3:
1. Defining functions
Def test6 (a = (), B = {}):
Print (' ############### #test6 ################ ')
Print (Type (a))
Print (a)
Print (type (b))
Print (b)
2. Calling functions
Call correctly:
Test6 (1, 2)
Test6 (A=1, b=2)
Test6 (A=1, b=2)
Test6 ((1, 2), {' C ': 8})
Test6 ({' C ': 8})
Test6 (b={' C ': 8})
Test6 ((1, 2), b=2)
Test6 ((1, 2), b=2)
Error Call:
Test6 (A=1, 2) #SyntaxError: non-keyword arg after keyword arg
Test6 (1, 2, b=2) #TypeError: Test6 () got multiple values for keyword argument ' b '