标签:UNC join form war 实参 显示 完整 def val
def ware_info(vendor_name, store_name, sku): return "{}商家下的门店{}不存在该品".format(vendor_name, store_name, sku) ware_info("北京XX","中关村店","10234567")
def login_params(phone, pwd, username): param = {"phone": "{}".format(phone), "pwd": "{}".format(pwd), "username": "{}".format(username), "loginType": 1, "setPwd": 0} return param #位置参数:基于位置 print(login_params("189000000", "123456", ‘DY‘)) #关键词参数:基于关键词指定 print(login_params(username="DY", pwd="123456", phone="189000001")) # 混搭 print(login_params("123456", "189000000", username="DY"))
引入*标记,“*”之后的都是强制关键字参数。
强制关键字参数的赋值必须显示通过关键字传入。
当强制关键字参数无默认值时,调用时必须给其赋值,否则报错;当强制关键字参数有默认值时,若调用时不给其显示赋值,其使用默认值。
def ware_info(*, vendor_name, store_name, sku): return "{}商家下的门店{}不存在该品".format(vendor_name, store_name, sku) print(ware_info(vendor_name="北京物美",store_name="中关村店",sku="10234567"))
def ware_info(store_name, sku, vendor_name="北京XX"): return "{}商家下的门店{}不存在该品".format(vendor_name, store_name, sku) ware_info("中关村店","10234567")
def my_method(a, b=[]): b.append(a) print(b)
def calc(*numbers): total = 0 for n in numbers: total += n**2 return total print(calc(1,2,3)) print(calc(1,3,5,7))
def get_info(name, sex, **kwargs): for msg, info in kwargs.items(): print("{}的性别为{}, 其他信息为".format(name, sex) + msg + ":" + info) get_info("张三", "女", store_id="12", store_name="zgc" )
def get_host(hostname, path=None, **params): url = "http://{}/".format(hostname) if path: url += path if params: param_list = [] for paramsName, paramValue in params.items(): param = "{}={}".format(paramsName, paramValue) param_list.append(param) url = url + "?" + "&".join(param_list) return url
print(get_host("cmsapi.dmall.com", path="/app/web/json", currentPage=1, isForceHome=0))
标签:UNC join form war 实参 显示 完整 def val
原文地址:https://www.cnblogs.com/dy99/p/14614272.html