 Hello everyone. Today, this week we're here going to investigate the world of Python classes. And before we get into the coding part of this week's module, first we're going to take a step up and make sure that we have a really strong grasp at an abstract level of what data types are. Now data types were a concept that we introduced last week. And you have worked with data types before. You've worked with ints and strings and floats, things like that. But let's talk a little bit more this week about how those things are realized within Python and how you can use your own custom data types to solve some interesting problems. All right. So, but again, to start out, I want to take a look at things from a higher level, an upper level. So data types. This is a concept that is common in every programming language. Maybe you're coming from a Java background or a JavaScript background. Doesn't matter. Every programming language has the concept of a data type. And a data type, what is it really? Okay, well it is two things and you definitely need to know these two things. First, data types contain data, of course, which is the information that you care about, like a number value, the characters in a string, right? Data. And that's the obvious thing. The other thing data types contain are operations. So the things that you can do to or with that data, right? So we'll see more concretely what we mean, but let's take a look at a metaphor here, a real world example. So I would argue with you that you could view make and model of a car as a data type. So here is a 2020 Kia Sorento LX front wheel drive. Okay, this is a car. But we want to think of it as a data type, right? A data type that represents this car. So data types have data and they have operations. Well, what's the data in a car? There is data to a car. There's its mileage, how much gas is in it, the presets on the radio, the VIN, the vehicle identification number. These are all data points that are kind of stored on the car somewhere somehow. Operations, what can you do with a car? You can go forward, you can go back, you can lock the doors, you can honk the horn, you can turn on the wipers, you can turn on the blinker, et cetera, et cetera, et cetera, right? Now here's the key, right? About a data type in Python and about this car that is also true. We're talking again about a very specific data type for this car, Kia Sorento LX front wheel drive 2020. The operations of this car are the same no matter which car you drive, right? There's lots of different Kia Sorento LX front wheel drives that you could go buy at a dealership somewhere, right? Maybe there's thousands of them, tens of thousands of them that Kia made. But every single one of them, you can do the exact same operations, right? Now if you change the car brand, its make, its model, even its trim, these operations might change. But for every single one of these, you do the exact same thing. The controls are the same, the buttons in the dashboard are the same, it's all exactly the same, smells the same, right? This is a data type. It's a particular type of car, they have, they all do the same thing, they all have the same operations, but they have a little bit different data inside of them. There are many instances of Kia Sorento's that are driving out there right now, all the same type of data, but they're different instances, right? The data are different. Your Eurodometer has different readings than myodometer. Your gas level is at a different level, your radio presets are probably different, right? Your VIN number is definitely different, the unique number that identifies your vehicle, right? So the data are different, but the operations are all exactly the same. So we've got one data type, this kind of car, right? This type of car, but there can be many different instances of this car driving around, okay? Same thing, let's look at a different example a little closer to the computing world. So a data type, I'm gonna say that the Spotify mobile playlist is a data type, right? So I'm talking about using Spotify on your phone here, and I know a lot of people do have it, right? I got it, you know, right here as well, okay? So let's think of the playlist that's inside Spotify as a data type, okay? What are the data here? Well actually there's not a whole lot of data in a playlist. There are the songs that are available inside your playlist, right? And then the name that's associated with the playlist, and you can call this whatever you want, this one's called classical faves, right? That's it for the data. But what can you do with this playlist? Well, you can shuffle the songs that are played, you can add songs to it, you can rearrange them, you can tap on them, get some more information, you can click this little download button to make sure they're on your device and not just streaming, right? So once again, this is a data, think of it as an example of a data type. The operations, now you can make your own playlist. What do your Spotify playlists look like? Well, they look like this, but they've got different data, you've got different names here, and you probably have different songs, right? So the data are different between my playlist and your playlist, but the operations are the same. You can shuffle, you can add, you can move these things around, you can play them, right? So data type, data, the stuff you care about, the information, and the operations you can perform on that data, all right? So now let's jump to the Python land for a minute and let's look at the string data type for just a second. I've got some Python code here, right? I'm assigning this string, Donald comma Trump comma 614 1946 to a variable, right? So this is a string in Python, string data type. And what am I doing? I'm stripping that string so I get rid of the backslash n, assign the new computed value to stripped. And then I do stripped.split on a comma. What does this do, by the way? If you call dot split, giving it a comma. Well, Python will take the original string, find every comma here, right? This one, this one, and break the string apart into substrings, Donald Trump 614 1946, and put them as elements in a list. Okay, so this is a list of strings now. All right, now maybe you want to do something with each individual element in this list, right? String manipulation, you've done it before, right? But how does this thing, right? So we've got this dot split thing here. Looks like a function call. It's actually technically a method. But what it really is in the terms we've just been talking about on the previous slide is split is an operation that is defined on the string data type, right? So how does this thing work? If I click on this, it'll take you to the source code for split, right? This is just splitting 390 lines. This is c and c++ code, okay? So splitting a string, if you were to like code it like real low level like you have on some of your other assignments, it's not simple, right? But frankly, you don't care. You don't care how it works, right? You just, your professor says, hey, split this string up into the substrings and put them in a list and you say, I've got the operation for that. It's called split. You don't care how it's implemented. Great. Good for you, right? It's useful, right? It's useful to not have to write the splitting of the code all by yourself. You might be able to imagine how you could, though, right? You could loop over this string until you find a comma and then say, oh, okay, everything up until the index of this comma, you're an element. And then everything up until the index of this comma, you're an element. It could be a lot of work actually. How about adding two integers? 42 plus 512. Well, these are data types. They're integer data types. But do you care, really, how the computer adds these things? Maybe you're interested, but it doesn't matter to you. What you're in search of is the sum, the result. And actually, if you go to Python, the source code for the integer data type is 5000 plus lines long, right? Adding integers, subtracting integers, multiplying. It's a lot of work to get it implemented properly. But thankfully, you don't have to do it. You just get to call this wonderful little plus operation, okay? So data types. Why do we have them? Because life is more productive when you've got these abstractions that take the dirty nitty-gritty details away, right? So this is the recipe for a Big Mac in theory. I'm told it's a recipe for at least something similar to a Big Mac. But you don't go into McDonald's and say, well, what I actually want is two thirds pounds of ground beef patty. That's 85% lean. I want to make it into four flat patties that will fit in the hamburger buns and put them in the freezer for a little while. Meanwhile, mix two cups of mayonnaise with yellow mustard. You don't say that. And if you went into McDonald's and did say that, you get a lot of funny looks. And in fact, I'll show you a video of a student who did just that on what I asked him to. So anyway, you can just go in and say, Big Mac, please. And they will produce one for you, right? Life in general is more productive with abstractions as is coding, right? You don't have to worry about how integers are added. You don't have to worry about how strings are split. You just do it. Why? Because you're interested in solving problems, okay? All right. So why classes? Why data types? abstracting away the implementation details allows you to focus on solving the big problem. The big problem is usually what your professor's asking you to do in the homework, right? But when you go take on a job somewhere, it'll be, Hey, I want you to find the people who spent the most time in the hospital this month. Okay, and they'll give you a big sheet of data. Well, how are you going to write some Python code to do that? You don't want to worry about the details of splitting strings or looping over files, you just want to do it. So that's why we have classes. You have been using built in data types built in classes all along in Python, right? Since day one, ints, floats, Boolean strings, lists, dictionaries, tuples, you don't care how they work. Maybe you're interested, but you don't care, they just work. So you want to use them. Now here's the thing we're going to explore the rest of this week. You can make your own classes to simplify the problem, or to simplify solving problems that you were given. Okay, so data types and Python classes is this week's subject matter. Data types, the general abstract notion of data types that are common in every programming language, are defined using classes in Python. And you have seen the word class. And I know some of you have probably experienced writing your own classes before. Totally fine. Data in Python are defined using classes. Data types in Python, like data types anywhere else are comprised of two things, the data you care about, that value, the number, the character, the whatever. Data are going to be kept in what we call class variables. Inside the class, we're going to think of a class as kind of a box, right? It's a box. And inside that box are things that you can do. Data is going to be kept in class variables inside the box. Operations are defined using what we call Python methods. And all the method is, is it's a function, a Python function that's inside the box of a class. Okay, that's it. When you create data in Python, not just with custom classes, but when you do something like x gets 42 or y gets 42 or name gets Alice, when you create data in Python in memory, you are making an instance of one of these Python classes. And collectively, when you've got a whole bunch of different classes, and different instances in memory, we refer to these things, things that live in memory in Python as objects. Okay, so next video, we'll get into some code and show you how to define your own classes and how to use them effectively.