JOHN ARTHUR
JOHN ARTHUR

Reputation: 43

no output from python class method

class animal:

    def __init__(self,name,tag):

        self.name = name
        self.tag = tag

    def build(self):

        return f"{self.name} is a {self.tag}"

class insect(animal):
    pass


animal1 = animal("Cow","4 legs,2 horns")
insect1 = insect("Spyder","8legs, small sized")

animal1.build()
insect1.build()

after implementing this script I am not getting any output please check it. but instead of return if given print function the output is shown

Upvotes: 0

Views: 58

Answers (1)

Seyed_Ali_Mohtarami
Seyed_Ali_Mohtarami

Reputation: 1164

Because your class used return, not print:

print(animal1.build())
print(insect1.build())

Output:

Cow is a 4 legs,2 horns
Spyder is a 8legs, small sized

Upvotes: 1

Related Questions