What is a Variable in Python?
A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing.
Every value in Python has a datatype. Different data types in Python are Numbers, List, Tuple, Strings, Dictionary, etc. Variables can be declared by any name or even alphabets like a, aa, abc, etc.
In this tutorial, we will learn,
Using the keyword global, you can reference the global variable inside a function.
- Variable “f” is global in scope and is assigned value 101 which is printed in output
- Variable f is declared using the keyword global. This is NOT a local variable, but the same global variable declared earlier. Hence when we print its value, the output is 101
- We changed the value of “f” inside the function. Once the function call is over, the changed value of the variable “f” persists. At line 12, when we again, print the value of “f” is it displays the value “changing global variable”