You can consider a variable to be a temporary storage space where you can keep changing values. Let’s take this example to understand variables:
So, let’s say, we have this cart and initially we store an apple in it.
After a while, we take out this apple and replace it with a banana.
Again, after some time, we replace this banana with a mango.
So, here this cart acts like a variable, where the values stored in it keep on changing.
Now, that we have understood what a variable is, let’s go ahead and see how can we assign values to a variable in python.
Assigning values to a variable:
To assign values to a variable in Python, we will use the assignment (=) operator.
Here, initially, we have stored a numeric value -> 10 in the variable ‘a’. After a while, we have stored a string value -> “sparta” in the same variable. And then, we have stored the logical value True.
Now, let’s implement the same thing in Jupyter Notebook and look at the result:
Assigning a value 10 to a:
Allocating “sparta” to a:
Assigning True to a:
Going ahead in this Python tutorial, we will learn about data types in Python.