Python 函数在调用后放置时不工作

Python 函数在调用后放置时不工作,python,function,Python,Function,有人知道为什么我在调用函数后放置它时,它不起作用,但如果我在它之前放置它,它会起作用吗 question = input("type any key to start") if type(question == str): game() def game(): print("Rock paper or scissors") 这不起作用。当我在开始时将def game()放在上面时,它起作用了。用以下方式重新排列代码: def game(

有人知道为什么我在调用函数后放置它时,它不起作用,但如果我在它之前放置它,它会起作用吗

question = input("type any key to start")
if type(question == str):
    game()

def game():
    print("Rock paper or scissors")

这不起作用。当我在开始时将def game()放在上面时,它起作用了。

用以下方式重新排列代码:

def game():
    print("Rock paper or scissors")
question = input("type any key to start")
if type(question == str):
    game()

您只能在函数定义之后调用它

在定义之前调用会引发一个
名称错误
,因为在调用时,没有什么可调用的。