0
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

1
  • 1
    well, if you print("foo"), you print "foo", and if you return "foo", you return "foo". what do you want to do? alternatively, you could do print(animal1.build()) to get the same effect as printing from within you function Commented Aug 12, 2021 at 14:26

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.