- The name of this video is Variables Lesson. So we're gonna start with variables, and variables are really the fundamental building block of code, and it's essential to understand them if you want to get good at coding. So, variables are part of what's called the data structure family, which also includes lists, tuples, and dictionaries. Now we're gonna talk about lists, tuples, and dictionaries later in the course. All of these things, all of these parts of the data structure family are used to hold data and move it around within the code. Lists, tuples and dictionaries are in a sense types of variables, and so all of the things that I talk about in this lesson that pertain to naming conventions really apply to those things too, they're just more, and we'll see more sort of complicated forms of variables. Now since this is the first lesson that I'm doing with a series of slides, I just wanna talk a little bit about the format that I'm using in these lessons. I'm using two different types of font. You'll notice this kind of bolder font up here I use for titling and any notes that I have. And then I use a different font for my snippets of code. And what I'm trying to do in that is I'm trying to emulate, I'm using the same font that you'll see in the editors, so I'm trying to get it to look like what it'll be in the editor. And I'm also using the same sorts of colors that you'll see in the editor like this function right here, this is a Python function called print, and it will show up in this type of blue in the editor. The other thing I do to reflect the format of the editor is I'll often give the lines of code numbers, which happens in the editor in the code editor in Rhino. The last thing is this output, so down at the bottom. And if we think about the sort of form of the editor, it's divided into three parts. It has the help part on one side, it has our, where we write our code, and then down at the bottom, it has a section that'll show us this output. And so rather than making a box in here, any time I list output, that's almost always referring to the fact that I'm printing something out, and it would be the thing that would sort of show up in this box in the editor. So, variables, now variables are a lot like the variables that you probably learned about in grade school when you took algebra. If you remember those sort of ABC variables of a triangle. There's something that stands in for something else. The difference with them in coding and the fact that we're using a computer is, not only do they stand in for something else, but they also are related to the computer's memory. So essentially what a variable is is a label that's put on a little piece of memory that we put some data in. Now, to assign a variable was actually a very simple thing. All I have to do is write the name of the variable, in this case x, and then I use the operator equals, and then it just follows with whatever I wanna, whatever piece of data that I want to put in that variable. And then anytime later in the code when I write that variable, what that's doing is it's looking at that little piece of memory, and it's accessing the data that I've stored within that piece of memory. This line here is called an assignment line. The line below it where I'm using that variable and I'm using another value here, which I've hard-coded into it, so it's not using a variable to carry the data, the data is just hard-coded into the code, and I'm using another expression which should seem familiar, a plus symbol, and I'm adding those two things together. This line of code is called an expression. So we have an assignment and we have an expression, and that expression uses this Python function print to print out whatever follows it, okay, within that line of expression. And the output is showing what it prints out, so 15. So fairly straightforward and understandable. Python is what's called a higher level coding language, which makes it very similar to reading English. So, if I have a variable and I want to reassign the data that's in it, all I have to do is overwrite it. So this example, this little snippet of code is showing, of course the assignment of five to the variable X, printing it out, which results in this output, and then in line three, I'm reassigning it, the data 10, which essentially overwrites that five, okay wipes that out, replaces it with 10, and then any time that I refer to x, from that point on, it's going to print out, or it's going to access the data 10. Now a good analogy for thinking about a variable is if you think of that little piece of memory as a file folder, and on that file folder you put a name, and that name is the variable. And so if I wanna access that space, that file folder, what I look for, what I use is the name. Now what do we put in that folder? Well we put data, we put all different sorts of data, and we have a lot of different things called data types, and we're gonna talk about that more in the next lesson. But, just to give you a little preview of that, it could be any number of things, so it could be integers, it could be none values, it could actually be other variables. It could be real numbers, they can be negative, it could be something called a string, which is a text-based piece of data. It could be true false statements, which are Boolean datas. Or it could be something that looks kind of strange, it's this really really long number here, and that's called a GUID, and we're gonna talk about that a little bit more when we talk about data types. So any and all of these things are stored within that folder, and then they're accessed by that variable name, whatever it is, XYZ. Or curve, or string, whatever we wanna call it. And we're gonna talk about those naming conventions a little bit next. So, there's a couple of guidelines associated with naming variables. The first one is gonna be a little hard to wrap your head around, and it's the fact that variable names are completely made up by you. They're completely made up by the programmer. So, in some ways they can be almost anything, but we really don't want them to be just anything because we want them to probably say a little something about what they're holding. They can be assigned anywhere in the code. Some coding languages may require you to assign the variables at the top of the code, you don't have to do that in Python, you can assign them anywhere in the code, you can reassign them anywhere in the code, there's a lot of flexibility with that. This next point is very very important. They're not only case sensitive, but they must be written exactly, exactly the same everywhere they are used in the code, or else Python's not gonna recognize them and you're gonna get an error. So if I use the word Dog, starting with a capital D as my variable name, it's not going to be the same as dog or DOG, writing dog all lowercase or all uppercase, those variable names just aren't going to work, if I'm trying to call up that data that I've held within the variable named dog. Python is gonna throw an error, it's not gonna understand what you're doing. And this is probably the most common error that early programmers will make, will be to write the variable name incorrectly after they have assigned it. Now there are a bunch of variable no-nos. Variables cannot begin with numbers, it doesn't mean we can't use numbers within variable names, like I often will write in the code crv01 and crv02, and that's fine. They can't contain spaces, so you can't have spaces between any characters within the variable name. They can't contain illegal characters, so things like exclamation points and hashtags, and anything that seems a little odd as a character, just don't use it within a variable name. And it can't contain any of Python's 35 keywords. Now you're gonna probably be wondering how am I gonna memorize these 35 words that I can't use as variable names? Well there's a good handy trick for that is in our editor that we're using, and most editors, Python editors you would use. When you write those keywords, they're gonna show up a little bit differently. So they're probably gonna turn a different color as I show here in the example of them. We're probably gonna, you'll also become very familiar with these. We're probably gonna use about half of these in this course, and so there's usually very little chance that you end up using them as a variable name. And naming conventions, very important. We like to use what's called a mnemonic naming convention, and all that is is a fancy name for give it a name, give that variable a name, which tells us a little something about what it's holding. So, in this example, I'm using STR to denote string. You don't know what a string is yet, but it's denoting a certain datatype, which is actually a text-based type that's defined between quotes and it will turn the color red in our editor, so I know it's a string. And then following that, I have a capital A, which denotes the second part of my variable name, and it's telling me a little bit of something about what the kind of string is that's being held there, and it's holding a string that's the name of an animal. And so that's different than let's say using A to denote the same piece of data. Although this is perfectly fine. If I use it exactly the same in the code from that point on, same way, write it the same way. It's gonna work absolutely fine. So again, I like to use these prefixes to denote a data type, and I'm gonna show you an example of some of those. And we also tend to use something called camelCase or an underscore where we have this sort of prefix in the initial part of the code and, or excuse me, the initial part of the variable, and then another piece of information that might be telling us something about the data it's holding in the second part of the variable name. Often sometimes people use underscore, people have different styles for using their variable name since they can make them up, and you will eventually develop your own. These are some of the common prefix conventions. A lot of these are related to, again, to datatypes, or they might be related since we're using Rhino, they might be related to particular types of geometry that we're going to use and bring in to the code. The examples on the right, the example names, you can see they're very self-explanatory, so this is, flt refers to a float, which is a real number. So that variable name is probably telling me something about, it's a distance value that it's holding, and it can be a real number, it can have decimals in it. Very important to remember and often difficult to sort of wrap your head around is the fact that a variable does not know what it's holding, okay? A variable does not know what it's holding. It means that there's no functional relationship between a variable name and what it's holding. This is often a very tricky point to sort of conceptually get beyond, but that's just the way it is. So, I can write string animal and I can put a string animal as a piece of data in that, but that doesn't necessarily mean that string animal is holding that type of data. It could be holding a real number. I could write a variable called points, it doesn't mean it's holding a series of point values. It could be a holding a string. It's true that I might be crazy, but just because I write bln as a prefix to a variable doesn't mean it's holding a Boolean value. So, that's a tough one to get through and understand, but you'll get it eventually. Again, these are conventions, they're not functional aspects of variables, but we use them for creating legibility within the code. And this is just to preview some of our data types that we're gonna be looking at, six primary ones. All these different types of data, again, are saved in our memory folder and given a variable name. And so that's variables. Again, these conventions are going to also apply to lists, tuples, and dictionaries so it's good to understand them at this point within the course. So one thing that's very important to remember, although it's a little bit difficult to sort of get your head around is the fact that a variable does not know what it's holding, which means there's no functional relationship between a variable name and what it's holding. So, for example, when I write str for a string, and then Animal, that doesn't necessarily mean that it's holding a string that represents an animal. It could be holding a real number. Again, there's no functional relationship between what this is and what this is. It's purely convention. So, if I write a variable called pts, it doesn't mean that it's holding a bunch of point values. It could be holding a string. It's still gonna work just the same. So, I might be crazy, but just because a variable starts with a bln prefix doesn't mean it's holding a Boolean value. So, that's really sort of I think a difficult concept to get, it was one that I had trouble with initially, I always thought the sort of plurality of variable names had some effect over what they could hold, but they don't. It's only for convention, but that convention is related to the legibility in the code. How do we look at a code and read the variables and at least get a hint at which, or what those variables are holding. And that's why you use these conventions, it's all about legibility. And so, in the next lesson, we're gonna take a look at the datatypes that are held within our memory folder, and access with our variable names. And we'll go through some examples of those. And that's variables. Again, these conventions are going to apply to tuples, lists, and dictionaries, and so it's very important to become familiar with them at this point within the course.