Variables

A variable is like a container that stores values that you can access or change. It is a way of pointing to a memory location used by a program. You can use variables to instruct the computer to save or retrieve data to and from this memory location.

A variable is a means of storing a piece of information using using a descriptive name. The use of variables is encouraged as it allows us to avoid having to repeat ourselves.

In Python, you declare a variable by giving it a value:

>>> my_variable=10

In Python variables are assigned using the equals sign.

>>> pi = 3.14

The meaning of the assignment operator (=) is different from equality in mathematics. In mathematics, = asserts that the expression on its left is equal to the expression on its right. In Python, = makes the variable on its left take on the value of the expression on its right.

Python is a lot more flexible when it comes to handling variables. If you need a variable, you’ll just think of a name and declare it by assigning a value. If you need to, you can change the value and data type that the variable stores during program execution.