Python Data Types
A free video tutorial from Colt Steele
Developer and Bootcamp Instructor
4.6 instructor rating • 9 courses • 788,073 students
Learn more from the full courseThe Modern Python 3 Bootcamp
A Unique Interactive Python Experience With Nearly 200 Exercises and Quizzes
29:43:09 of on-demand video • Updated May 2020
- Learn all the coding fundamentals in Python!
- Work through nearly 200 exercises and quizzes!
- Learn about all of the latest features in Python 3.6
- Use Python to create an automated web crawler and scraper
- Make complex HTTP requests to APIs using Python
- Master the quirks of Python style and conventions
- Really Really Understand Object Oriented programming in Python
- Learn testing and TDD (Test Driven Development) with Python
- Write your own Decorators and higher order functions
- Write your own Generators and other Iterators
- Confidently work with Lambdas!
- Master tricky topics like Multiple Inheritance and Polymorphism
- Build games with Python
- Build larger projects that span across multiple files
- Work with all the Python data structures: lists, dictionaries, sets, tuples, and more!
- Become an expert at list and dictionary comprehensions
- Master built-in python functions like zip and filter
- Handle errors and debug code
- Write your own custom modules
- Work with files, including CSV
English [Auto] All right. So we've been working with numbers. It's kind of boring. I know we've been working with one in 99 and 73. All very great numbers especially 73 that's a great number but very limited. So we might use numbers to do things like I don't know store the price of something that's a really common use case or the quantity we have in stock like we or Amazon we're selling peanut butter. We want to say this peanut butter is three dollars forty nine cents. So price is 349 and quantity is 900. That's great. That's useful. But of course there's a lot of other things that we care about that aren't numbers. What about the name of the peanut butter. What about the date it was made. We could use a number for a date. But is there a better way. What about a description. What about images. There's all these other things that we need to care about. But at the end of the day everything we do in a variable it has to be a valid data type in Python. So we can't just make something up. We have to follow the rules. It's kind of a thing in programming. So with python there are a bunch of data types that we get out of the box things that Python says OK here what you know you have integers. We've already seen those. You have floats which are like numbers or integers but there's a decimal point but there are other things and so some of them are here on this table. But I want to be clear this is not comprehensive. These are probably. Well definitely the most commonly used ones. But we'll learn more as we go. So I just wanna make sure you don't walk away thinking there are only five types. For example floats which we've been working with are not listed here but that's a data type. So in this video I'm going to just walk through some of these very quickly. So I don't feel like you have to hang on to every word because things like lists and dicts dictionaries are going to have their entire their own sections devoted to them. All right. So let's kick things off by talking about booleans. It's kind of a weird word weird sounding thing if you haven't heard of them before but they are just yes or no. True or false values on or off. So think of binary 0 and 1. That's what our computers are built on top of this little circuits. Bits of light that are flashing on or are not flashing. Yes or no. So you could use a number to store a yes or no value. We could say OK if it's number one it means it's on. And if it's number two it means it's off for that. True or false. But if all we want is true or false there's no reason to allocate the entire space for an integer because remember integers could be really really long and that an amount of space has to be allocated in memory. But if we're saying this is a yes or no value that it's only going to make a little bit of space to store true or false. That's not the only reason that it's useful. We're going to have a whole section on Boolean logic later on. But let me just show you an example. So here I am in my terminal in Python 3 so I can just type the word true like this has to have a capital T by the way or a capital F for false. That's how Python knows it's a boolean. I could just type it like I could type 981 and get the return value back but I could save it to a variable as well. So I could do something like is active and set it equal to true and I look at is active and I get true or I could have a variable called Game Over and I could have game over start out as false. So this is actually a really standard way of writing games like tic tac toe or any game where the game keeps going until you lose or until you die or until someone wins. We could have game over set to be false. And then at the end of the game we said it to be true and the game is over. Now obviously there's a lot of logic that goes in between those two things. The thing I need to point out though is that we can't do this lower case t because it's no longer boolean. So Python recognizes it based off of that capital. It's a special thing a special idea reserved for false and for true. So if I do this it tells me Hey true is not defined. I don't know what you're talking about. So uppercase really important. So I know it seems silly at this point. Boolean values but they are very useful and it's not just a shorter way or a more compact way in memory to store yes or no values. There's actually a lot of operations that we get that work with booleans that we'll see later on. OK so next up we're going to talk about strings strings. We're going to devote the rest of this section too. But the idea is that they're just characters could be numbers but a lot of times it's words and letters and symbols. Basically any Unicode character. So they're in-between quotes single or double which we'll talk about later but they're inside of quotes so could be my name colt or some Chinese characters or it could be just the number two inside of quotes that makes it a string not a number. So here's an example let's just call it some string. I could set it be set it equal to the number 8. And if I look at some string remember that we have this thing type let's do type of some string and it tells me hey a string as TR versus doing type of eight itself isn't it. So I can also do some string equals and instead of quotes I'll do hello. I am a string and I'll put an exclamation point just to show you it's not just numbers and letters it's any valid Unicode character. And now I look at some string and we get that back. OK so string's not going to waste too much time in this video on because we will spend a lot of time with them in this section. They're very very useful. So this is how you would probably store things like the name of an item on your store something like jar of crunchy peanut butter. Even those smooth creamy is inarguably better. We could store that with a string. All right. So then the last tube. I'm going to go through at lightning speed because like I said they each get their own section. But these are more advanced data types sort of like they evolved through a level up in that they actually store other types of data inside of them. They're what's known as data structures. So the first one is called a list and it's an ordered sequence of values. So here's an example. One two and three. Or the strings. AB in-seat stupid examples. But the idea Well it needed to be short to fit in this table. But the idea is that you can store data inside of them in a list and there's an order. So maybe we have a waitlist on my shop I'm sold out of my peanut butter. It's delicious homemade peanut butter and make up my roof I guess with those peanuts. They don't grow. I have a list of people who are interested. I need an order to it. Right I don't just want to have a variable for each person I need them to be grouped together and somebody is first. So whatever's first in the list. OK. Then we have dictionaries and dictionaries are a bit different. They work. There's no order. First of all. But more important than that we have pairs of corresponding values stored together. So here's an example where we have first name is set to Colt and then last name is set to steal. So rather than having two separate variables we can put them together by using a dictionary which is what these braces signify just as these brackets here signify a list. So if that makes no sense to you I wouldn't I wouldn't sweat it. We're going to spend a lot of time working with these are really common. But the main difference again is that these are more basic data types booleans integers float strings. And then we have these data structures lists and dictionaries that actually store other bits of data. OK. So that's it for now. There's a lot of data types. This is not comprehensive but really we're going to focus on strings for the next couple of videos.