In computer programming, variables are a fundamental concept related to how you store as well as process data. Let's take a look at what this means. Please run every code cell in this lesson in the same order as I do from top to bottom. This is important if you don't run every call cell in the same order, you might have unexpected errors pop up. Let me start by illustrating this with a code snippet. I'm going to say age equals 28. And what this does, is it creates a variable and stores the value 28 to it. So now if I say print age guess what this will do. This prints out the number 28. Let's look in detail at what just happened here. With the line of code Age equals 28. What you're telling Python to do is to create a space which you can think of as an empty box, to store the number 28. And so whenever I use this variable age, Python knows I mean 28. Now I can decide to change what age stores. If I were to have a line of code that says age equals five this is my daughter's age. Then what this is saying is, forget the old value that we stored in the box 28. Let's get rid of that and store the value five inside this box instead. So now age is equal to five. So to illustrate that in code, at this moment age is equal to 28. But if we were to now say age equals five and then print age, age has now been replaced with the number five. Variables can be used to store strings or numbers. In the example we saw, we assign the value 28 to age. Or you can have a variable called name and assign to it the string Otto. Or if you have a garden gnome, you can create a variable called gnome height and save the number 12.7. Let's take a look at how this works in code. So, I'm going to say name equals Otto, gnome height equals 12.7. And if I were to use an f-string to print the variable age, this would print age five. And similarly now that I've set name to Otto and gnome height to 12.7, I can print name Otto gnome height 12.7. When you're defining variables, it's important to use the exact same name. So, if I were to change this to Gnome height. This will won't work, this will generate an error message. See I've used the exact same name for it to be correct, and switching from lowercase uppercase confuses Python. So, variables can be used to give a value like someone's age, a name to use later in one or more places. Another common use of a variable is to use the same name to refer to a value that changes. So, for example, if you are playing the game of Tetris, your score may start off with zero, but after you play for a while, your score increases to 50, and then 150 and then 450. And after the game ends, you save the high score to memorialize your accomplishment playing Tetris. In this example, you score may start off as zero. But then after you've earned another 50 points in the game, we can set score equals score plus 50. So, what this means is take the old value of score at 50 to it and use the assignment operator To your computer, please take the old value of score and replace it with the new value of score which is score plus 50. And now if you've earned another 100 points then take the old value of score which is 50 add 100 to it. Store that in the box labeled score. And so now your scores's 150. If you earn another 300 points in the game now the score's 450. And if you say your final score score this would print 450. Now some things about variable names. If you were to try my score equals 450. This generates an error message because the names of variables cannot contain spaces in them. If you want a space, use instead an underscore like that. And that will work. If I haven't told you this. You can also find out from the chatbot on "why doesn't this code work?" And this will then tell you see, you can put an underscore or just eliminate the space. Let's look at a fun dog age example. Let's say our friend Otto is 49 years old. And so if you want to compute his dog age, you would print 49 divided by seven, which is seven. If you want to print out Otto's dog age, you could do so like this. Otto's age in dog years is 7.0. I can define the variable dog age equals 49 divided by seven. And now dog age is going to be equal to seven. And where this comes in handy is if I want to write a paragraph of text that refers to Otto's dog age multiple times. Before we had variables, you couldn't write this it's just a little bit annoying to have to write forty nine divided by seven multiple times, and if, Otto ever becomes a year older, then we need to go to the code and change this to 50 in multiple times. There's actually a better way to do this, which is, you could use this code to print out the same result having computed dog age just once. And if ever Otto ages by a year, you can actually set dog age equals 50 over seven. And then if I rerun run this code, it now updated in all the different places. So, by defining a variable once you could use it in multiple places. And this is why variables help make computer programs much more efficient. You can also even change out the name, Otto. If you decide you want to refer to Otto by his last name as well, like Otto Matic. Then you can rerun this code and you have his full name printed out in all three places. Otto Matic. I hope you got that joke. Just to walk through in detail how f-strings and variables work together. This is the example we had just now where the dog age was seven. And so when Python finds dog age in curly braces, this causes it to check for a box with the name dog age, whereupon it finds the number 3.0 and replaces that part of the f-string with 3.0. And similarly for the other two places, which is why it then prints out the string that you saw in the code. This f-string pattern that you see. where you have some text and you insert the value of a variable to customize the string. It turns out this pattern is one that is very useful for customizing the prompt that you can then pass on to an AI language model using a Python program. So, please take some time to practice using f-strings and variables together by trying out the exercises below. Talk to the chatbot to help you resolve any problems you might encounter. And when you're ready, join me in the next video to take a closer look at using f-strings to build prompts for large language models.