1 關鍵字參數
所用情形:參數太多時,防止參數順序對函數的影響,傳參時指定參數對應的形參名
>>> def test(brand,slogan):
print(brand + "'s slogan is " + slogan)
>>>test(brand='Nike',slogan='just do it')
Nike's slogan is just do it
2 默認參數
>>> def test(brand='Nike',slogan='just do it'):
print(brand + "'s slogan is " + slogan)
>>> test()
Nike's slogan is just do it
3 可變參數 參數前加 *
>>> def test(*params):
print('參數的長度是:',len(params) )
>>> test(1,2,3,4) #實現形式參數打包成元組
參數的長度是: 4