參數匯總
阿新 • • 發佈:2018-08-16
style 形參 默認 匯總 col ddr 廣東 函數 北京
1 #coding=utf-8 2 ‘‘‘ 3 函數參數 4 ‘‘‘ 5 6 #位置參數:實參與形參的位置必須對應,否則會引起意想不到的的情況 7 def z1(name,address,age): 8 print(‘name is {},address is {},age is {}‘.format(name,address,age)) 9 z1(‘張三‘,‘北京市北京西路‘,100) 10 11 #默認參數:需放在位置參數後面,有實參取實參,無實參取默認 12 def z2(address,age,name=‘李四‘): 13 #變化越小的放在越後 14 print(‘name is {},address is {},age is {}‘.format(name,address,age)) 15 z2(‘北京市廣東西路‘,101) 16 17 #關鍵字參數:關鍵字無需考慮位置,實參賦值時需要放在位置參數後面 18 def z3(name,address,age=110,xingbie=‘男‘): 19 #變化越小的放在越後 20 print(‘name is {},address is {},age is {},xingbie is {}‘.format(name,address,age,xingbie)) 21 z3(‘王五‘,‘北京市北京西路‘,xingbie=‘女‘)
參數匯總