Variables are an essential thing in all programming languages. They help us reuse multiple values more than just once.
One special thing about Python is the implicit type-inference. This means, that we do not have to assign a type to a variable by it's declaration as in Java or C. That means that the compiler does the typing by itself.
Types in Python Edit
In Python we can assing variables of many different types:
Usage of variables Edit
To assign a variable, we use this general Syntax:
variable_name = value
Now see some examples:
# declaring two strings foo = 'foo' bar = 'bar' # declaring an integer # note: automatically inferred as integers i1 = 7 i2 = 42 # declaring two floating point numbers d1 = 42.7 d2 = 7.42 # declaring two complex numbers c1 = 7 + 42j c2 = 42 + 7j
Reuse of variables Edit
The main thing about variables is that we can use them more than just one time by calling them. This is done as in the following example:
# defining a variable foo = 'awesome' # ... and reuse it by # printing it's value print(foo) #in Python 3.X # print foo #in Python 2.X