Quiz Catalog

Catalog of quizzes

name = 'Tom'

def greeting():
  global name
  name = 'Bob'
  print(f'Hello {name}', end = ' ')

def farewell():
  print(f'Bye {name}')

greeting()
farewell()
Hello Bob Bye Bob
  • scope/global

def outer():
  num = 5

  def inner():
    global num
    num = 25
    print(num, end = ' ')

  inner()
  print(num)

outer()
25 5
  • scope/global
  • function/inner

num = 2

def increment():
  global num
  num = num + 1
  print(num)

increment()
3
  • scope/global