Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Local vs. Global Variables | Variable Scope, Nested Functions, and Closures
Functional Programming Concepts in Python
Sektion 3. Kapitel 2
single

single

Local vs. Global Variables

Stryg for at vise menuen

Opgave

Swipe to start coding

Create a function that demonstrates the difference between local and global variables by modifying a global variable inside a function.

  • Use the global keyword to modify the global variable x inside the function;

  • Assign the value 20 to x within the function;

  • Create a local variable y inside the function and assign it the value 5.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 2
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

some-alt