What is the difference between the variables of Python and other language

If you are from C/C++/Java and started learning Python, this should be an interesting topic for you.

In languages like C, C++, Java, PHP etc a variable is a memory location where its value is saved. When you copy a variable into another variable, both of them still in existence and you can use both of them.

But in Python, its different. As a matter of fact Python don’t have any variables, it has ‘name’ or ‘identifier’ attached to an object (everything in Python is an object).

Let me clear this using an example:

In other language:

int a_variable = 1; //Here a_variable has a value of 1.

a_variable = 2; //Now a_variable has an updated value of 2.

int another_variable = a_variable; //Now another_variable is a new variable with a value of 2.

int sum = a_variable + another_variable; //you can still use both of the variables.

In Python:

a_variable = 1  #Here integer object 1 (see, everything is an object) has a name tag (or identifier) ‘a_variable’

a_variable = 2 #Now a_variable name tag is now attached to integer object 2. Old integer object 1 can’t be accessed via a_variable anymore.

another_variable = a_variable #Now both another_variable and a_variable name tag is attached to integer object 2.

Though we still call them variables in Python, but you see, they behave differently (almost like the pointers in C).

I hope it helps. Let me know your comments 🙂