Let’s start with data types. So a variable, such as our age variable or our person variables, can be of many types. So far we’ve dealt with numbers and with text, which is known as ‘strings.’
The remaining three main data types are lists, tuples, and dictionaries.
Now we’ll get to these three types in a later on in a different tutorial, but for now we’ll just be learning about numbers.
We’ve already dealt with the basics of numbers such as:
age = 10
students = 20
You know the basics of how to add these numbers to variables. That’s basically the core concept of using numbers. Now what we want to learn is to add variables or subtract variables…
The way we do that is with something called operators. You probably already know what these are: addition, subtraction, multiplication and division. Four simple operators.
Let’s make two variables:
age1 = 19
age2 = 52
So let’s quiz here. Make a third variable, age3, which is the sum of age1 and age2. How would you do that?
It’s actually quite simple. Do it this way…
age3 = age1 + age2
This is how we use operators. So now if you print out age3 you’ll be given the sum…71. That simple!
That was addition. Now let’s try subtraction, division, and multiplication.
age1 – age2
That subtracts and gives us -33.
Divided, which gives us…0.36538461538461536!
Multiplication; the sum is 988.
Now the last operator I want to talk about is, at least for arithmetic operators, is modulus.
All it does is give you the remainder of a division. So we had divided age1 by age2 and got 0.365…and so on.
age1 % age2
That’s how you use the mod to get the remainder.
Written for my own study of Python as I journey to learn it. I’m following the instructions from this YouTube video, and this section of the tutorial begins at 12:33