Python Variables

Now you can print things with print and you can do math. The next step is to learn about Python variables. In programming a variable is nothing more than a name for something, similar to how my name “Akar” is a name for, “The human who wrote this book.” Programmers use these variable names to make their code read more like English, and because they have lousy memories. If they didn’t use good names for things in their software, they’d get lost when they tried to read their code again.

Let’s take an simple example for this we can use X and assign it a value 23 and when we need it we call it and use it.

This is a perfect example to explain all about variables. Now run this code

To use any variable we need, to define it use “=” symbol. We can use math algorithm on python variables and use them as many time as we want. You can use a variable multiple time in a script and redefine it in can if required. A variable can be assigned to another variable also.

But wait we have defined cars_driven in our code then why does python throw an error? That’s because we have define cars_driven in line number 3 and are using it in line number 2. We have to define the variable before we use it.