Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

How to call method in the class in python ?

By M.K. Verma · 3 May 2022

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