3. Numbers in Python | Get paid course for Free | Comment Down your Language |


Hi guys and welcome back. In this video we’re going to learn about numbers and mathematics in Python. You’ve got two main types of numbers, and that is integers, or whole numbers, and floating point numbers, or numbers with a decimal place. For example, if we do age equal 35, this is an integer, and if we do PI equal 3.14159, this is a float. Notice that the variable name itself is largely irrelevant in this explanation, what matters is the value. Here we’ve got a whole number, a number that doesn’t have a decimal place, and here we’ve got a number with a decimal place, so this is a float. Anywhere in Python you can also use the hash symbol to write a comment. So here we have something called an integer, and here we have a float, and what happens is when Python goes through this code, it ignores everything that comes after the hash symbol so you can use it to write comments for yourself, to remind yourself of what things are, or as notes for studying later on. Mathematics works just as normally, so we can have a variable called maths operation and make it equal to one plus three, times four, divided by two minus two, making use of all the major mathematical symbols, and just as in normal maths, the PEMDAS or BODMAS rules are followed, so multiplication is evaluated first, then division, then addition, and then subtraction. So here we would have 12 divided by two is six, one plus six is seven, minus two is five, and you can verify that by printing it out, so I’m gonna press run now and we see 5.0 gets printed out there. This is an important part of mathematics in Python because whenever you do division, you always get a float, even if the result is essentially something point zero, which is basically a whole number, you always get back a float. So if we do something like float division, and we say 12 divided by three, and we print it out, and I’m just gonna delete this code here for simplicity, so if we do something like this, you’ll see that we get 4.0 back. If you want to get rid of the floating point, or the decimal place, you can do integer division. So here I’m gonna create a new variable called integer division, you can call it whatever you want though, remember these are just names, and I’m gonna do 12 divide divide three, and what this does is it performs the division and then removes everything after the decimal place, so this can come in handy at times. So, if we run that you see that you get 4.0 first from this first print statement and then just four for the second one. Notice that if we change this to eight divided by three, the floating point division is two point six, but the integer division is two. This here does not round the numbers up and down, it just removes everything after the decimal place, so this is something to keep in mind as you do integer division later on. That’s everything for this video, thank you for joining me, and I’ll see you in the next one.

Leave a Reply

Your email address will not be published. Required fields are marked *