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

Kursinnehåll

Intermediate Python Techniques

Intermediate Python Techniques

1. Mastering Packing and Unpacking in Python
2. Mastering Function Arguments in Python
3. Function as an Argument in Python
4. Understanding Variable Scope in Python
5. Mastering Python Decorators

book
Challenge: Modifying a Global Variable in Python

Uppgift

Swipe to start coding

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.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 3
toggle bottom row

book
Challenge: Modifying a Global Variable in Python

Uppgift

Swipe to start coding

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.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 3
Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Vi beklagar att något gick fel. Vad hände?
some-alt