python 2
python 2
This site uses Google AdSense ad intent links. AdSense automatically generates these links and they may help creators earn
money.
Python Variables
Variables are containers that store information that can be manipulated and
referenced later by the programmer within the code.
In python, the programmer does not need to declare the variable type explicitly,
we just need to assign the value to the variable.
Example:
Scope of variable:
The scope of the variable is the area within which the variable has been created.
Based on this a variable can either have a local scope or a global scope.
Local Variable:
A local variable is created within a function and can be only used inside that
function. Such a variable has a local scope.
Example:
foods()
Output:
Global Variable:
A global variable is created in the main body of the code and can be used anywhere
within the code. Such a variable has a global scope.
Example:
foods()
print(icecream + " is a global variable value.")
print(fruit + " is a local variable value.")
Output: