Get startedGet started for free

Understanding scope

What four values does this script print?

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)

This exercise is part of the course

Writing Functions in Python

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise