Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Modifying a Global Variable | Variable Scope
Intermediate Python Techniques

book
Challenge: Modifying a Global Variable

Tarefa
test

Swipe to show code editor

This task shows how you can modify a global variable from within a function using the global keyword.

  1. Use the keyword global for receiving access to modify global_var;
  2. Increase global_var value on to 5;
  3. Call the function modify_global to implement changes;
  4. Print modified global_var.

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 3
global_var = 10

def modify_global():
___ global_var
___ += 5

___()
print("Modified global variable:", ___)

toggle bottom row
We use cookies to make your experience better!
some-alt