From the course: Python for Non-Programmers

Numbers: Ints and floats - Python Tutorial

From the course: Python for Non-Programmers

Numbers: Ints and floats

- [Instructor] Now that you know what variables are, we're going to start learning about types. And what are types? Types in Python are just the different type of things that we can put inside of a variable. So for example, in this video, we're going to be learning about ints and floats, which are two number types. So let's start first with ints. Ints is just short for integer. It means a whole number. A number that doesn't have any decimal places connected with it. So for example, in the challenge from the last video, I had said day is equal to 21. This is an example of an integer, right? It's a number that doesn't have any decimal places. So we have this variable day. It's set equal to the integer or int of 21. Now integers can be positive or they can be negative. Let's say it's a really cold day outside and the temperature is negative 15 degrees. We can say temp is equal to not just 15, but also negative 15 degrees. So again, whether it's positive or negative, as long as it doesn't have decimals, it is an integer. And this brings us to our next type, which is floats. Floats are numbers that do have a decimal place connected with them. So for example, when I'm tracking my weight, I like to be very specific. I like to go down to the decimal on it. So for example, I might record my weight as equal to 190.4. For me, that .4 is very important. I want this specific number and this is an example of a float. It has a number with a decimal on it and it doesn't just have to be one number after the decimal, like we could get really specific here, and with floats, they can also be positive or negative. Just like integers, they go on each side. So with these two types, what can we do with them? Well, a really cool thing that we can do with Python is some math. So anytime we want to do some type of calculation, we can do addition, subtraction, multiplication, division and we can use the different variables that we have. So let's go ahead and on a new line, let's print out and just do some math without variables and then we'll do them with some variables. So for example, I want to know what three plus six is. I can simply just type that inside of my print line here. And if I go ahead and hit the Run button, in our console, we'll see three plus six is nine. Okay, that's cool. What if we want to see what day is today three days from now? We can say day plus three. This will give us the date in three days. So if I go ahead and run this, you can see that day was equal to 21, then we added three on top of it, and now, we're displaying the number 24. The 24th is three days from the 21st. Some other things that we can do if you want to do some multiplication, if I want to see what my weight is doubled, I can type weight times, and to represent multiplication in Python, you use a star symbol or an asterisk, and then the number two. So I'm going to take my weight and times it by two, and there, we can see it's 380.8. Some of the other types of math that we can do are division. For division, we just do a forward slash. So let's see my weight divided by two. That is 95 pounds. And we can also do subtraction with the minus sign, okay. So those are the basic types of math that you can use in Python and you can see how we can work with variables that, again, are holding these different types and using them to do some great math. So it's time now to make sure that you've got a good grasp on what we learned here. Let's do a challenge. I want you to find something around you in your life to represent an int and also a float and put them inside of variables. So for me, I like weighing myself down to the decimal. Find something around you in your life that you can count using a decimal and also something with an integer, okay. Hit Pause, do that now. Alright, hopefully that went well for you. For me, I'm going to represent my age as a whole number. I'm going to say that my age is just 32. Then, I really like cryptocurrency. I'm going to say that I went and bought some Bitcoin. I got 0.00435 Bitcoin, okay. You can see this is a float 'cause we've got a very specific decimal here.

Contents