Python | Variables

A variable is just a container where you can store and manipulate values. The syntax to define a variable in Python is variable_name = initial_value. So, to define a variable you have to give it a name and assign it a value.

name = 'Dan'

The = sign is not the mathematical equal sign (not in this case). It is an assignment operator which takes what is on the left hand side and assigns it on the right hand side.

Open the terminal and type name = 'Dan'. The computer will store the variable for you and allocates space for it in memory. You can refer to the variable by name and print it on the screen.

You can also define more than a variable at once.

name,age = 'Dan',40

See, the terminal window below.

Python variables

Variable names must start with a letter (after that you can use underscores, letters, and numbers).
There are Python keywords that can not be used as names for variables. They are words reserved for Python.
Python is case sensitive (name is different than Name).

Leave a Reply