message
is declared inside the greet
function. It is accessible only within the function and works perfectly when the function is called.message
is a local variable, it cannot be accessed outside the greet
function. Doing so results in a NameError
.message
is declared globally, so it can be accessed both inside and outside the greet
function.global
keyword. This explicitly declares a variable as global, allowing it to be accessed outside the function.global
keyword ensures that the variable message
is accessible outside the greet
function.message
inside the greet
function does not affect the global variable message
. They exist independently within their respective scopes.global
keyword makes the local variable message
overwrite the global variable. As a result, the global variable’s value is updated.global
Keyword: Converts a local variable into a global one.global
.global
keyword?global
keyword, changes made to a variable inside a function only apply locally and won’t affect the global variable.global
keyword inside the function.