开始使用免费开始使用

理解作用域

这个脚本会打印出哪四个值?

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 函数编写

查看课程

动手互动练习

通过我们的互动练习之一,将理论转化为实践

开始练习