Transcript for:
Understanding Variables and Data Types in Python

All right, everybody, we are moving on to variables. A variable is a container for a value. There's four different data types we'll discuss. Strings, integers, floats, and booleans. Yes, I know, that's a silly name. A variable behaves as if it was the value it contains. Each variable should have a unique name. Let's say we have a variable of first name. To assign a variable, you use the assignment operator of equals. For text, a string... is a series of text. This can be double quotes or single quotes. My own preference is double quotes. Why don't you type in your first name? This variable, a first name, will behave as if it was this value, this series of characters. So to demonstrate this, I'm going to print my first name variable. So place it within a print statement without quotes. That will print your first name. Now you don't want this within quotes, because then you're literally printing the word first name. You could use your variable along with some text by using what is called an f-string. That's the easiest way to display a variable. So you type f, then a set of quotes. The f means format. So let's say the word hello, then we will add our variable. We will insert our variable into this text when using an F string. To do that, you need a set of curly braces, then insert your variable. So the result is, hello, whatever your first name is. In my case, bro. Let's create another variable. Let's say we have a variable of food. Food equals, think of your favorite food. For me, I will type pizza. Let's print the following. You like, add a placeholder, again I'm using an f-string, our variable of food. Hello bro, you like pizza. Let's create an email. Use your own email or make up one. Let's say my email is bro123 at fake.com. Then let's print our email. Your email is... Add a placeholder. Display our email variable. Your email is bro123 at fake.com. So these are strings. I'm going to add a comment that these are strings. A string is a series of characters. They can include numbers, but we treat them as characters. Now we have integers. An integer is a whole number. An example of this could be somebody's age. How old are they? According to my YouTube statistics, many of you are between the ages of 18 through 24. Let's say that I'm 25. Let me zoom in a little. Your integer should not be within quotes, because it would be a string then, technically. If I would like to work with this variable, again, I'll use an f-string. Let's say you are, add a placeholder, display our age variable, years old. You are 25 years old. Another example of an integer could be a quantity. You are buying a certain amount of something. Maybe I am buying three items. I wouldn't have half an item. This would be a float, technically, rather than an integer. We are buying three of something. So let's print the following. You are buying, at a placeholder, display our quantity, items. You are 25 years old. You are buying three items. Another example of an integer could be an amount of people. Let's say num of students, like a classroom. There are 30 students in our class. Then we will print, Your class has, at a placeholder, students. We will display the number of students, num of students. Your class has 30 students. Those are integers. They're whole numbers. And again, make sure they're not within quotes. Because then technically they would be a string. Integers we can use in arithmetic expressions. If they were strings, we couldn't. Then we have floats. Float means floating point number. A float is a number, but it contains a decimal portion. An example would be a price. What is the price of something? 10.99. Let's print our price. Print, I'll use an F-string. The price is, add a placeholder, display our price. The price is 10.99. Let's pre-seed our placeholder with a unit of currency. I'll pick American dollars, but feel free to pick something else. The price is $10.99. So floats contain a decimal portion. What about a grade point average, GPA? Let's say my GPA is 3.2. Then I will print, your GPA is, display our GPA. Your GPA is 3.2. What about a distance? A distance can contain a decimal portion. 5.5 kilometers, maybe. Then I will print, you ran, add a placeholder, display our distance, then I'll add km for kilometers. Or you could add mi for miles, but I'll stick with kilometers. You ran 5.5 kilometers. Okay, then we have booleans. A boolean is either true or false. Let's say we're a student. Is student equals. If we are a student, we could say that this is true. True starts with a capital T. If we weren't a student, let's say we graduate, we could say that this is false. Again, the first letter is capital. Booleans only have two options, true or false. So let's say that I am a student. Then I will print, are you a student? Then we will display our Boolean value of is student. Are you a student? That is true. With Boolean values, we really don't output them directly. You're more likely to see them used internally within a program, such as when working with if statements. This is a topic we'll discuss in the future, so don't worry. You may see if. isStudent if this variable is true. Then we will print the following. Now we don't need to use an f-string, we're not going to insert any variables. You are a student. If this were false, we can add an else clause where we will print you are not a student. Our variable of isStudent is true. we will print the if statement. You are a student. If this were false, we will print whatever's within else. You are not a student. Let's think of a few more examples. Is something for sale, like a car or a product of some sort? Let's say that is true. I'll write another if statement. If forSale, if this variable contains true, we will do the following. Let's print that item is for sale. Else, if it's false, we will print something else. That item is not available. For sale is set to true. This variable is true. We will print that item is for sale. Else if it were false, we print that item is not available. One more example. Let's say we have a Boolean variable of is online. Is somebody online? I will set that to true. If isOnline, if that's true, we will print you are online. Else we will print you are offline. isOnline is set to true. We will print, you are online. Else, if it were false, we print, you're offline. All right, everybody, so those are variables. A variable is a reusable container for a value. There's four basic data types for beginners. A string, which is a series of text. Integers, which are whole numbers. Floats, which are numbers, but they contain a decimal portion. And booleans, which are either true or false. They're binary. Your assignment in the comments section is to post four variables. Post a string, an integer, a float, and a boolean. Try and think of a unique example if you can. And well everybody, those are variables in Python.