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

single

bookLocal vs. Global Variables

Swipe to show menu

Task

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.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt