Course Content
Intermediate Python Techniques
Intermediate Python Techniques
Local Variable
A local variable is defined inside a function. You cannot access this variable outside the function's definition.
def greet(): message = 'Aloha' print(message, '# local message') greet() print(message) # This line will result in an error
The output is:
The <strong class="go98639658">message</strong> variable is not accessible in the global scope; it exists only inside the function. When the function exits, this variable ceases to exist.
Thanks for your feedback!