将多个字符串传递给函数并附加到列表
Passing multiple strings to a function and appending to list
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, trick ):
self.tricks.extend(trick)
我一直收到这样的错误:add_tricks 只接受 1 个位置参数,但给出了 3 个。我尝试将 **kwargs 传递给该函数,但这也不起作用。如何将多个字符串传递给函数?
For (*args) parameters as ("Hello","Byy")
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, *trick):
self.tricks.extend(trick)
For (**kwargs) parameters as (a="Hello",b="Byy")
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, **trick):
self.tricks.extend(trick)
Or if you want to give string in both types like (a="Hello","byy")
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, *trick1,**trick2):
self.tricks.extend(trick)
self.tricks.extend(trick2)
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, trick ):
self.tricks.extend(trick)
我一直收到这样的错误:add_tricks 只接受 1 个位置参数,但给出了 3 个。我尝试将 **kwargs 传递给该函数,但这也不起作用。如何将多个字符串传递给函数?
For (*args) parameters as ("Hello","Byy")
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, *trick):
self.tricks.extend(trick)
For (**kwargs) parameters as (a="Hello",b="Byy")
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, **trick):
self.tricks.extend(trick)
Or if you want to give string in both types like (a="Hello","byy")
class Dog:
tricks = []
def __init__(self,name):
self.name=name
def add_tricks(self, *trick1,**trick2):
self.tricks.extend(trick)
self.tricks.extend(trick2)