Python Forum

Full Version: Hangman game, feedback appreciated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(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.
Pages: 1 2