Jack Hoff.
Jack Hoff.

Reputation: 143

Cannot see where is the error in my simple code

In the following, why it is not printing results even though I don't see any errors:

class Test(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def printing(self):
        var = self.x + self.y
        print(" RESULT= %i " % var)


if __name__ == '__main__':
    Test().printing(10, 20)

Upvotes: 0

Views: 37

Answers (1)

xiº
xiº

Reputation: 4687

if __name__ == '__main__':
    Test().printing(10, 20)

Should be

Test(10, 20).printing()

You have mistake in instance initialization.

Upvotes: 3

Related Questions