Basic Data Types Recorded Transcript This transcript was created with a speech to text software. Please excuse any typos or mismatches with the video. Hi, welcome back in this video. We're gonna dive into some Python with some basic data types. So this is gonna be a very basic level video on Python. We'll learn things about data types. Uh And this is gonna be very low level. So if you have some experience with computer programming or even a little bit of experience with Python before you may be OK to skip this video. I encourage you to scroll through the basic data types notebook. See if you're OK. Uh Without going through it all. Uh If you do feel like you need to go through it, we're gonna go ahead and get started right now. So in this notebook, uh we're going to introduce what are known as basic data types in Python. Again, I'm assuming that if you're going through this video, you have no knowledge of coding, no knowledge of Python, just a, a knowledge of some, you know uh elementary school, high school mathematics uh and then uh a a working functioning computer. So we're gonna learn about things like comments in Python types, integers, floats, booleans as well as some very basic Python operations, things like addition, subtraction how to do them uh in Python. So let's talk about comments versus code in Python. So in Python, you can write code like we did in the my Jupiter notebook video like two plus two and we can execute it and get out four. Uh But what we can also do is write what's known as a comment and a comment is a piece of text that you'll write in the code to sort of explain what the code is doing. And it's good practice to do this uh for not just yourself but for anybody else else that might read your code at a later date. Uh And I said, not just yourself, but it's actually really important for yourself. There are many times when you might write some code, uh set it aside for a few weeks or a couple of months, maybe even a couple of years and then you'll come back to it and not remember what the code does because you didn't comment it well. So the way that we can write comments in Python is with this hashtag or pound sign symbol. So here we had some code two plus two. But if I type the hashtag or pound symbol in front of it, now, it is seen as a comment which means that when I hit shift, enter, it's going to register that this code is not to be run as it instead exists as a guide for coders at a later date. So here we do not see the four. And so I wanna make a quick note that this pound symbol is only going to affect the line on which it is typed. Uh So for instance, if I go back here and I write two plus two underneath it, this second line is now going to be seen as code and will be executed if I run it. Whereas this first line is not seen as code and we can, you know, maybe make it a little bit more clear instead of doing two plus two again, what if we did three plus three? And so here we see a six. So hashtag symbol or pound sign, that's a code. Uh that's a comment. It will not get executed as code, uh something without a hashtag symbol or without a pound sign uh is seen as code and will be executed and the symbol only impacts the line uh to the right the stuff to the right of it on a single line. So here's an exercise for you that I'm not gonna, you know, you can pause the video and do it or you can do it at a later date, try writing a comment for yourself down below uh and then move on with the rest of the video. OK? So now that we have some base level knowledge of, here's how you write some code, uh syntax wise, here's how you write a comment. Let's start diving into data types. So data types are basically how your computer parses and stores different types of data. So for instance, numbers or letters, uh so the first type of number that we're gonna talk about is a data type is an in which stands for integer. And so integers members are counting numbers and the negatives of them. So like 12 negative 71 these are all integers. Uh And if you have some familiarity with other programming languages, you might be wondering well, how large or how small can these gets? Uh So like what are the bounds on the Python three integers? In Python three, there is no known, there's not like a set bound for each computer. It depends on the hardware of your laptop or your desktop computer. Uh wherever you're running the Python on. Uh if you have good hardware, you can get as high probably as you'd like. Uh I think in today's age, you're probably gonna be able to get as high as you would like uh with these integers again, within reason uh for a link to the documentation on in, if you'd like to read further on your own is clicked here and I'll click on it just to show. So this is documentation. Uh It's written by whoever wrote the code that you're looking into. So here we can see the class in and so this is uh an integer object. Um So this good practice in the future, we're going to get the stuff that isn't as straightforward as in. So just being mindful of documentation now uh is useful for us later. So let's see some examples. So the number four is an in and here's a little piece of Jupiter notebook stuff that we didn't touch on in the last notebook. Uh But here, whenever you execute a code chunk, the last thing that is written on here. So for us, the four, the last thing that's executed is what the output is. So for instance, if I put a three here, that three isn't shown because there's something that's executed after it, which is the four. OK? Uh We'll see more of this in a little bit. All right. So once you have something, maybe you want to know is this, what is this thing? Is it an in what's the type of this object? You can also get the type of an object in Python with the uh type function? OK? So if I put the number four in the function type I get out in. So here are gonna be some exercises, I'm gonna do them right now. But if you want to do them on your own, pause the video and come back and see what I did to uh compare your work. So what's the type of two integers added together? Well, I should hope that it's an integer but we'll see. So let's do three plus eight. So that's an in, what about if I multiply two integers? Uh My guess would be that this is also going to be an inch 34 times seven, ... in. Uh And what about if I divide one inch by another? Well, let's see. So let's do one. So four divided by two. Interesting. It's a float. So what's a float? Well, A float is what's known as a floating point number. So this is the way that your computer stores things that are not integers. So even though four divided by two is an integer, if we look at four, divided by two in a code chunk, you'll see what gets returned is 2.0. So this is while two is an integer Uh when you perform a division, it's always gonna be seen as what's known as a decimal. So a decimal number. So two as a decimal is 2.0 if we did say three divided by two, we'd get 1.5. So these are all decimals and the way your computer represents a decimal number is with floating point uh numbers. So these are any real number. And then depending on the number you have, this is within reason. Uh there's some precision that's determined by your computer's hardware because there are numbers that just cannot be represented by a computer, particularly a number like pie cannot be exactly represented in a computer, right? Because our computers cannot create an infinite sequence of numbers. Um but for all intents and purposes, the pie that we'll see in these Python notebooks is pretty close, close enough to the real pie for our purposes. OK. So here is again a link to the documentation on floats in Python if you'd like to read more. So as some examples, the number 3.2 is a float. All right. So again, more exercises you can do this on your own, pause the video and come back. I'm gonna go through them right now and you can check your work when you're ready. So type of four divided by three is a float. All right. What happens? Uh If I put 2.3 in an in. So let's take a second. What do you think's gonna happen? So, in to remember was a type, uh what does it mean? Is it also a function? What is a function? I guess we haven't really talked about that too much. We will soon. Uh But what are we doing here? Well, when we put in uh 2.3 into in, we get out the number two. So that's weird. I thought 2.3 was a float. What if I check the type here? ... So the type of this is also an in and so we could look it up if we'd want to. Uh But I'm just gonna tell you what it does. So when you put something inside of in, it's going to try to the best of the function's ability to cast that uh as an integer. So when you put a floating point number into the in uh function, it's going to round it down to the next closest integer. So it will always round down. Uh maybe I'll be wrong, but I'm pretty sure it's always gonna round down. So what if we put in 2.9, which is a number we would typically round up. So see it rounds down to two. Uh So in rounds, uh a floating point number, rounds it down to the next closest integer. Uh And we'll see in a little bit that in can't turn everything into an integer, but it tries to do its best. OK. OK. So now that we have some numbers, we have integers, we have decimals known as floats in Python. Uh What are some numeric operations that we might want to do? Well, here are the four common ones, addition, subtraction, division and multiplication. These should all be familiar to us. There's something called exponentiation. Well, this is when I do something like two squared or two to the fourth. That's what I mean here. So you would write two star star four. If you want to do two to the fourth in Python, there's something called modular division which gives you the remainder from a division problem. So if you remember back in the day when you were learning how to do long division, uh depending on where you went to school. Uh You would have like that little symbol here, right? You draw your own line, what you're dividing by what you're dividing and then there would be like a remainder over there. So the remainder is what you get with modular division. So three mod, which is how we say modular division three mod two would be 15 mod two would also be one. And so that little percent sign uh we would pronounce this as five mod two. There's also floor division which is gonna give you what remain or like how many times uh the thing you're dividing by goes into the thing you're dividing. So for instance, seven uh floor divided by two is three. Uh And then there's some special note here about what would happen if you try to floor divide it. Uh a negative number. Here it goes the other way. So seven uh negative seven floor divide by two instead of being negative three would be negative four. OK? So here are some more exercises. Uh go ahead and try and figure them out on your own and then I'm gonna do them right now. Uh But pause the video and do them on your own if you'd like to and then come back when you're ready. OK. So two to the seventh. So I need exponentiation, which according to us here is two stars. So two star star seven 78 Modulo 13. So this is modular division. So I do 78% symbol 13 because that's modular division ... turns out I chose two numbers that 13 divide 78 perfectly. Uh And then negative 1 92 floor divided by uh 27. So I do negative 198 /27. OK. So negative. Uh so this is um 27 goes into a negative 198 uh at least to negative seven times. And we may have, you know, rounded down, right according to this rule. OK. So we've got ints, we've got floats, we've got some things that we can do to them. Uh What's next? Something called a bull. So a bully, a bull is a bullying or a logical object. So all we mean here is something that is true or something that is false. So uh these are the ways that we will keep track of whether or not something occurs and these are gonna be really important and something called conditional statements in a little bit which we'll learn about in uh a future notebook slash video. Uh So true means that something is true and false means that something is false. Uh which is also maybe the same as saying not true. So these are incredibly useful as I said. And in Python, they're literally just coded as true or false. Those are the only two options. So capital T and capital F, that's important. So if you have something that's true, it will be recorded as capital T R U E. If you have something that is false, it will be uh a capital fa L S E and we can notice here that the capital is important. So if I did a lower case, we'll see here. Name true is not defined because it sees this and thinks that it's a variable which we'll talk about also in another notebook. OK? So another key thing to point out in Jupiter. So true with a capital T and false with a capital F are keywords in Python. They're important. They have a predefined meaning and you can't change them and same with in float and type. So typically when that is the case, Jupiter, when you're typing them will color them as green. So if you see something that's colored as green, that's usually because it's an important word in Python and you shouldn't use it for other purposes. Uh Like what are known as variables which again we'll learn about in a future notebook. OK? So again, we have some more exercises for you to go through, I'm gonna go through them with you right now. Uh You can do them on your own or you can uh go do them with me if you'd like to, whatever works for you. So what happens when I put false inside of in, let's see. So in turns false into zero, that's pretty standard. What happens when I put a zero? Inside of bull, which is gonna try and cast it as a bull in. Well, what we should hope to happen is that it will turn out as false and that's what it does. OK? What happens when I put false inside of in ... turns it as two A zero. Uh uh We already did that. So this should actually be, this is a typo good thing. This should be true. It will be uh corrected on your version of the notebook. So what happens when I put true inside of it? I get one. What happens when I put one inside of bull? I get true. And now here's the last one. What happens if I put 3.14 inside a bull? Weird, right? So it also comes back as true. So as a quick note here uh in Python, if you try and cast something as a bull, a number as a bull, as long as it's not zero, it will come back as true. So every nonzero numeric in Python, so every nonzero number in Python is going to be true if you try to cast it as a bullion. OK? Zero is reserved as the single false one. So just keeping up with our numeric operations, here are some additional operations for booleans. You can see if one is greater than the other that's gonna result in a bullion. Uh If you have a number that's less than another number that you know, trying to compare two numbers that way will give you a bullion result. These will also give you bullion results. So we've got greater than, or equal to, less than, or equal to equal to or not equal to, which is the exclamation point with the equal sign. We can see if more than one thing is true at false with either typing the word and, or using the symbol. And we can see if uh any of this collection of things are true using the word or, or the vertical line and we can negate something, meaning that if it's true, we turned it into false or if it's false, we turn it into true uh using the word not. So if we were to do, we can kind of think of this as a silly joke. Uh So you would be like, I want something that is not true, which is the same as saying that's false. OK. So let's go through and check. Uh These are again, exercises, feel free to pause and do them on your own and then come back and check with me. So we've got is 50 greater than two. Well, let's see what Python has to say and we should know it already. Hopefully. So that is true Is 50, not equal to 50. So there's a couple ways we could do this, we could do 50 ... Exclamation point equals 50. OK? Or we could also conversely do not 50 equals to 50 right. And then finally is 50 greater than two and 10, less than three. So we can do. Here's the key thing we're gonna have to put it in parentheses. So, is 50, greater than two, so 50 greater than two and 10, less than three. ... OK. We could have also done, ... I'm gonna copy this, we could have also done instead of the word and we could have used the Ampersand I believe is what that's called. OK. All right. So that's it for this notebook. You now have a good feel for Python's most basic data types. We will use this to build even more complicated data types and future notebooks. Uh But for now we know things about integers, floating point numbers and bulls a very good starting point. All right. So that's gonna be it for this notebook. I will see you in the next video and have a good rest of your day.