Let's learn abut how to use variables in Python.
Changing Variable Value
Similar to making a new variable, you can change the value of an existing variables the same way.
Python automatically understands whether a variable already exists or not.
If the variable does exist, it will be changed. :::
If variables are no longer needed or needed for a different purpose, you can delete them.
It can be done with the
name = 'Coding-Insight'
However, if we run the following code, it gives an error.
name no longer exists.
Declaring Multiple Variables
To declare multiple variables, list out all the variable names on the left side of the assignment operator.
And put in all the values on the right.
a, b, c = 1, 2, 3
print(a, b, c)
The example above prints
1 2 3 because a is
1, b is
2, and c is
If we want to declare all the variables with the same value, we can use the
= while linking all the variabels and putting the value on the vary right.
a = b = c = d = e = 'alphabet'
print(a, b, c, d, e)