Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Local Variable | Variable Scope
Intermediate Python Techniques
course content

Course Content

Intermediate Python Techniques

Intermediate Python Techniques

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

bookLocal Variable

A local variable is defined inside a function. You cannot access this variable outside the function's definition.

123456
def greet(): message = "Aloha" print(message, "# local message") greet() print(message) # This line will result in an error
copy

The output is:

The message variable is not accessible in the global scope; it exists only inside the function. When the function exits, this variable ceases to exist.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 2
We're sorry to hear that something went wrong. What happened?
some-alt