0
How do i print out a object from __init__ to main()?
Class Cat: def __init__(self, catname): self.catname = catname def give_name(self): self.catname = "Tony" def return_catname(self): return self.catname def main(): cat_object = Cat(catname) print(cat_object.return_catname())
1 Resposta
+ 4
1 class is lowercase
2 check your indentation levels
3 pass a valid string or variable to the constructor
4 call the main function to run it
#How do i print out a object from __init__ to main()?
class Cat:
def __init__(self, catname):
self.catname = catname
def give_name(self):
self.catname = "Tony"
def return_catname(self):
return self.catname
def main():
cat_object = Cat("Kitty")
print(cat_object.return_catname())
main()
If you're going to use methods to access and modify your class members then you should change the access modifiers of those members.
IE cat_object.catname is accessible.