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)
I keep getting the error that add_tricks only accepts 1 positional arguments but 3 were given. I tried passing **kwargs to the function but that didn't work either. How do I pass multiple strings to the function?
Solution 1:
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)