germanjke
germanjke

Reputation: 519

How to autorun methods in a class?

i have class A {1st stage}

class A:
    def __init__(self, arg1, arg2):
        self.arg1 = arg1
        self.arg2 = arg2
    def print1(self):
        print(self.arg1 +' World!')
    def print2(self):
        print(self.arg2 + ' is smart')

I'm identify arguments: {2nd stage}

hello = 'Hello'
cat = 'Cat'
a = A(hello, cat)

if i will use {3rd stage}

a.print1()
a.print2()

i will get {4th stage}

Hello World!
Cat is smart

My question is how i can call my methods by autorun? I mean without {3rd stage}. To just identify arguments and object of class and get the output

Upvotes: 0

Views: 72

Answers (1)

The_Pingu
The_Pingu

Reputation: 192

you can call your methods in __init__

def __init__(self, arg1, arg2):
        self.arg1 = arg1
        self.arg2 = arg2
        self.print1()
        self.print2()

Upvotes: 2

Related Questions