Python Constructor not showing anything on IDE -
trying create class constructor reason im failing misarably when testing..
class person(object): name="" age=0 city="" def __init__ (self,name,age,city): self.name=name self.age=age self.city=city #just testing def addperson(person): person1 = person() person1.name="test" person1.age=1 person1.city="here" print(person1)
process finished exit code 0. nothing happening. know basic maybe im not seeing here. ?
if that's code, you're not instantiating object. add code ( on left, not in class):
p = person("fernando", 99, "city") print(p.age) print(p.name) print(p.city)
and output should be:
99 fernando city
you defined class, doesn't until create instance of shown.
Comments
Post a Comment