Python函数中参数* 和 ** 的区别
* 函数接收参数为元组
例如
def myfun(*args): #相当于 def myfun(1,2,3) ==> args 就相当于(1,2,3)
for a in args:
print(a)
** 表示函数接收参数为一个字典
def myfun(**args) :#相当于 def myfun({a:1,b:2,c:3}) ==>args 就相当于{a:1,b:2,c:3}
for k,v in args:
print(k,":",v)
比如:
def find_element(self,*local): return self.driver.find_element(*local) username_loc = (By.XPATH,"//*[@id='username']") def type_username(self,username): #注意此处,需要写作:*self.username_loc self.find_element(*self.username_loc).clear() self.find_element(*self.username_loc).send_keys(username)