0
Please complete this code.
class Dog: def __init__(self,name): self.name="name" dog=Dog def__str__(self): #What should I write here?
2 Answers
+ 4
abas , Sawa Abraham ,
just saying `... please complete this code ...` is not enough information what the code should achieve. can you update your post ?
there are also 2 issues that prevents the code from running properly:
> ...
self.name = "name" does not assign the parameter that is passed to the class instance but just assigns the string `name`. should be:
self.name = name
...
>...
def__str__(self): missing space after `def`, the method that should do the output should be defined as:
def __str_(self):
...
+ 2
class Dog:
def __init__(self,name):
self.name="name"
def__str__(self):
'''you can put a string that will displayed any the print function in used on the class instance'''
return f"{self.name} is my dog"
dog = Dog("max")
print(dog)
# output: max is my dog