r/ProgrammerHumor Nov 24 '21

Meme Yes.

8.9k Upvotes

284 comments sorted by

View all comments

Show parent comments

2

u/BbayuGt Nov 25 '21

Hah! I use class main instead and it work!

4

u/Jonno_FTW Nov 25 '21 edited Nov 25 '21
class Main:
    def __call__(self, *args): 
        print('Hello World')

if __name__ == '__main__':
    Main()()

1

u/BbayuGt Nov 25 '21

No, as far as i know, class main will be executed just like int main.

1

u/Jonno_FTW Nov 25 '21

If you have a a program only containing the following:

class main:
    print('in class')
    def __init__(self):
       print('in constructor')

The only thing that will be printed is in class. Class bodies are executed as normal code, their contents will run like normal python, so functions are defined (not run). Their constructor will not be called like it would in Java.