Global Variables

Here is an example of a global variable in action.
x = 34

def add45():
    global x
    x = x + 1
    return x + 44

print (x)
print (add45())
print (add45()) 
Returns:
34
80
81

Global variables are often said to be dangerous. This is due that is not clear what a function is actually doing if we keep we depend in external references, this is to be considered when using global variables.




Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.
Tkinter - Learn the key features of the tkinter to allow you to create user interfaces for your python programs.


Related Pages

Pickle - The pickle library allows a program to save data in a binary file.
Python - List Comprehension - Create powerful list comprehension expressions.
Python - Generators - Learn about generator statements.
Python - Data types - The learn about the key datatypes in the python language.
Tkinter - Combo Box - This is a short example showing how to use combo boxes in a GUI.
Tkinter - Radio Buttons - A short example of how to create a GUI with radio buttons.
Tkinter - Canvas - Canvas allows for a range of shapes to be plotted, such as circles, squares, lines