52.python收集参数
52.python收集参数
def print_params(*params): # *接受元组,一个星号 print(params) def print_params2(tt2, *params): # *接受元组 print(tt2) print(params) def print_params3(tt2, *params, **params2): # *接受元组,*接受字典 print(tt2) print(params) print(params2) # Press the green button in the gutter to run the script. if __name__ == '__main__': print_hi('PyCharm') # 收集参数 print_params(11, 22, 33) print_params2(11, 22, 33, 55) print_params3(11, 22, 33, 55, f1=98, f2=97)
#参数收集的逆过程
def print_params3a(tt2, *params, **params2): # *接受元组,*接受字典 print('print_params3a') print(tt2) print(params) print(params2) print(params2['name']) print(params2['city']) # Press the green button in the gutter to run the script. if __name__ == '__main__': print_hi('PyCharm') # 收集参数 print_params(11, 22, 33) print_params2(11, 22, 33, 55) print_params3(11, 22, 33, 55, f1=98, f2=97) params3_dic = {'name': 'dashan', 'city': 'BJ'} print_params3a(11, 22, 33, 55, **params3_dic) # #参数收集的逆过程
欢迎讨论,相互学习。
cdtxw@foxmail.com