語法 :: global 陳述句

  • 在函式中使用
def f():
    global x = 1 # SyntaxError: invalid syntax
print(x) # NameError: name 'x' is not defined

def f():
    global x
    x = 1

print(x) # NameError: name 'x' is not defined

f()
print(x) # 1

results matching ""

    No results matching ""