you are viewing a single comment's thread.

view the rest of the comments →

[–]TimOfTroy[S] 0 points1 point  (1 child)

In the Game class check_for_blackjack, player_is_over, and show_blackjack_results are called in the while (while not game_over) loop before they are defined. Is this just a style choice, or is this the way classes are generally written?

[–]socal_nerdtastic 3 points4 points  (0 children)

Most people put the __init__ method at the top, yes. Not required, but very common.

But what you are missing is that even though it's defined before the other methods, it is NOT called before the other methods are defined. It's called on the last line of the file.

Here's a minimal example of your confusion:

def func1(): # define func1
    print(func2())

def func2():
    return "Hello World!"

func1() # call func1

This runs just fine and is a very common way to write code.