Transcript for:
Understanding Variables in Programming

alright welcome back in this video you'll learn about something that is a fundamental aspect of just about every programming language variables let's dive in and look at a program that has a variable in it in a minute we'll take some time to go over exactly what a variable is and what it does the variable in this program is called greeting it has a value which is hello world this means that printing greeting is basically the same as printing hello world here's another program with a variable the variable is called my number and its value with the number 50 ok so what is a variable a variable is something that stores information in a program so that it can be used later that information can be something like hello world or the number 50 more specifically a variable has three things a name a type and a value so let's look at the two variables that we just saw and spell out each of these three characteristics in the case of variable greeting the name of the variable is greeting the type of the variable is ster which I'll explain in a second and the value is hello world in quotes note that when you print the variable greeting you don't put quotes around it then we saw a variable whose name was my number whose type was int which I'll also explain in a second and whose value is 50 okay so what do these types mean stur is short for string a variable whose type is ster contains text or a sequence of zero or more characters and these characters can be letters numbers punctuation spaces whatever you can type on your keyboard so hello world is an example abc123 is an example or a string can actually have zero characters okay quick digression strings can also be surrounded by single quotes in Python however in this course we will use double quotes now let's look at the type int int is short for integer and a variable whose type is int contains a number and that number can be positive negative or zero however it cannot have a decimal component so negative 50 0 and 5 are all examples of integers another type that we haven't seen yet but we will in future lessons is float float is short for floating-point number and this is basically like an integer except it does have a decimal component so negative three point two zero point zero or four point five six five two are all examples of floats note that the Cemil component can be zero so zero point zero is in fact equal to the integers zero you can create a new variable or update an existing variable in python using what's called an assignment statement this statement has three parts on the left you have the name of the variable on the right you have the value that you want to give to that variable and in the middle you just have a single equal sign okay check out this example program in the upper right unlike the program that we saw a few slides ago this program prints the type of the variable greeting rather than the value you can do this using the type function the output is class stir in triangle brackets and this might look a little weird but the important part is the part inside the single quotes stir which is in fact the type of the variable greeting now we can see the type function being used on the variable my number and sure enough the type is int so that's the basics of variables in Python in future videos you'll learn how to do more interesting things with a variable than just print its value or its type