-1

i tried to use multiple function in class using init method. following problem occur

class Person1:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def say_hi(self):
        print("hello", self.name)

    def age(self):
        print("age",self.age)

p = Person1('kashindra', 21)
p.say_hi()
p.age()

File "", line 16, in TypeError: 'int' object is not callable

2
  • Define age inside of class Person1 Commented Sep 8, 2019 at 3:19
  • don't use the same name in Class for variable self.age and method def age(self) Commented Sep 8, 2019 at 3:25

1 Answer 1

1

In your class, you defined age as a variable, but you also defined it as a function. What you need to do is rename the function.

class Person1:
    def __init__(self, name, age):
        self.name = name

        self.age = age

    def say_hi(self):
            print("hello", self.name)

    def say_age(self):
        print("age", self.age)

p = Person1('kashindra', 21)
p.say_hi()
p.say_age()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.