Udemy

Python Data Types

A free video tutorial from Colt Steele
Developer and Bootcamp Instructor
Rating: 4.7 out of 5Instructor rating
25 courses
1,507,639 students
Data Types Overview

Learn more from the full course

The Modern Python 3 Bootcamp

A Unique Interactive Python Experience With Nearly 200 Exercises and Quizzes

29:40:29 of on-demand video • Updated April 2023

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 kind of boring and 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 if we were Amazon, we're selling peanut butter. We want to say this peanut butter is $3.49. 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, okay, here are what you have integers. We've already seen those. You have floats which are like numbers or like 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 want to 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 don't feel like you have to hang on to every word because things like lists and Dick's 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 zero and one. That's what our computers are built on top of these 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, okay, if it's a number one, it means it's on. And if it's number two, it means it's off or that it's 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 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 three, so I can just type the word true like this. It 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 nine, eight, nine 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 can have game over set to be false and then at the end of the game we set 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 lowercase t because it's no longer a boolean. So Python recognizes it based off of that capital F, 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. Okay, so next up, we're going to talk about strings. Strings we're going to devote the rest of this section to. 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 quote. So it 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 eight. 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, it's a string str versus doing type of eight itself is an int 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. So strings. I'm 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 though smooth and creamy is inarguably better. We could store that with a string. All right, so then the last two 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. They're 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 A, B and C, 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 wait list on my shop. I'm sold out of my peanut butter. It's delicious. Homemade peanut butter they make on my roof. I guess with the peanuts, I 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. Okay, 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 cult and then last name is set to steel. 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. They're 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. 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.