Why is Python beating Java these days

Python course

Variables in other languages

This subsection is specially intended for C, C ++ and Java programmers because these programming languages ​​treat standard data types differently than Python. Those who learn Python as their first programming language are welcome to skip to the next subsection.

In most programming languages, such as C, it is the case that a variable designates a fixed memory location in which values ​​of a certain data type can be stored. The value of the variable can change during the program run, but the value changes must be of the same type. So you can't have an integer stored in a variable at a certain point in time and then overwrite this value with a floating point number. The storage location of the variables is also constant during the entire run, so it can no longer be changed. In languages ​​such as C and C ++, the storage location is already fixed by the compiler.

What we've said so far applies to languages ​​like C, C ++, and Java. In these languages, variables must also be declared before they can be used.

int x; int y;

Such declarations ensure that the program reserves memory for two variables named x and y. The variable names stand for the storage location. It's like the two empty shoeboxes in the picture on the right. These two shoeboxes are labeled with x and y. Like the shoeboxes, the memory for x and y is empty.

If you want to store values ​​in memory, you can do this with assignments. The way you assign values ​​is the same in most programming languages. Most of the time the equal sign is used. The value on the right is stored in the variable on the left. In the following C example we will assign the value 42 to both previously declared variables. We can also see the result illustrated in the picture.

x = 42; y = 42;

It is not difficult to understand what happens when we assign a new value to one of the two variables, for example the value 78 of the variable y.

y = 78;

The value of the location of y has been exchanged.

We have now seen that in programming languages ​​such as C, C ++ or Java, every variable has a unique data type or, better, must have. This means that if, for example, a variable is of the integer type, it can only accept integer values. In these programming languages, variables must also be declared before they can be used. Declaration means binding to a data type, which is then unchangeable for the entire program flow.

Variables in Python

In Python we have an entirely different situation. First of all, variables in Python do not denote a specific type and therefore you do not need a type declaration in Python either.

At the beginning we have already seen that variables are created or changed through assignments: