開始使用免費開始

理解作用域(scope)

這段指令碼會印出哪四個值?

x = 50

def one():
  x = 10

def two():
  global x
  x = 30

def three():
  x = 100
  print(x)

for func in [one, two, three]:
  func()
  print(x)

本練習屬於課程

Python 函式寫作

檢視課程

動手互動練習

將理論付諸實踐,立即體驗我們的互動練習

開始練習