Python Forum
Hangman game, feedback appreciated - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: Hangman game, feedback appreciated (/thread-11566.html)

Pages: 1 2


RE: Hangman game, feedback appreciated - buran - Jul-19-2018

(Jul-19-2018, 08:44 AM)WolfWayfarer Wrote: @Windspar: so there is a main() in Python too!
well, it's just a perception for main entry point in your script. you can designate any function to be the main one :-)

def foo():
    print('foo')

def bar():
    print('bar')

# this would be your 'main'
def enter_here():
    foo()
    bar()

if __name__ == '__main__':
    enter_here()
in python more important for the structure of the code/execution/imports is the use of if __name__ == '__main__': pattern/block. E.g. the above can be just
def foo():
    print('foo')

def bar():
    print('bar')


if __name__ == '__main__':
    foo()
    bar()
i.e. what you would put in your 'main' function it just can be inside if __name__ == '__main__': block. Using 'main' function doesn't hurt but is more or less a reflection of your programming habits/patterns from other languages.