alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

How to call method in the class in python ?

How to call method in the class in python ?

When you creating a class, you need to follow the basic principles of class realisation. You forgot about __init__ function which initialize you class, you code need to looks like:

 class TestClass:
    def __init__(self):
        super().__init__()
        
    def repeat(self, txt:str, num:int):
        counter = 0
        while counter < num:
            print(txt)
            counter = counter + 1 

And then all will works

 testing2 = TestClass()
testing2.repeat('test', 10)
#test
#test
#test
#test
#test
#test
#test
#test
#test
#test

33 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online