 Hey everybody, this is Brian and welcome to the second Python tutorial. We're just going to jump right back on in here. If you watch video one, we did the Hello World program. We're going to kind of continue on with that, make a new Python file here and we'll call it the very descriptive video two. And like I said in the intro, we're going to cover this as if you're very new to programming. So if you're a veteran programmer, you can probably fast forward through a lot of this and just kind of pick up the highlights. There are a couple little things and I'll try to point those out. So in every program, you need to leave comments and a comment is this. Just a comment. It's you letting yourself know what you're doing. At some point you're going to get stuck, you're going to write some big long function and you're going to want to write a comment saying, hey, this is what I did. The comment is not processed by the Python processor, if that makes any sense, meaning it's just a note for you. The program doesn't care. So you can type literally anything you want. Probably best to put a descriptive note. Comments are good. So always keep that in mind. We're going to save this little guy here. Now the core of any program is a variable. And I'm sure your instructors, if you're in a university, have said a variable is this sector of memory that a pointer points to and your eyes start glazing over and you start thinking about playing hockey or video games or Call of Duty or whatever. All you need to know is a variable is something that will change. That's the actual literal scientific term for it. A variable is something that will change. In Python, variables are very easy. So we're just going to say, whoops, if I could actually spell first, equal, and Brian's my first name. We'll say last, equal, and Karens is my last name. And age, oh boy, I don't know if I want to put this out on the internet, I'm 40 years old and we're going to actually make a comment here. These are variables. Now if you try running this, you'll see it does absolutely nothing. It just says we ran, and then whatever the name of the script is, and finished with exit code zero. Exit code zero. Does that mean it's an error? No. Actually, code zero means there was no error. Programs will return different codes and those codes are usually called error codes. If you have Windows and you've ever seen the infamous blue screen, it's got some big garbly number. That's the error code. So exit code zero is a good thing. What we're going to do now is we're going to learn how to print things out. We already did the hello world. We're going to say print in all its glory. That's what this tutorial is all about, is printing. So we're going to say print, and we've done the hello world. So that's nothing new. You can also print and do single quotes, hello world. What's really the difference here? If we just run this guy, you can see it both prints hello world. What's really the difference? Nothing actually. It's just personal preference. The single quotes make it easier to put a quote in the string, and the double quotes make it easier to put a single quote in the string. Because let's say you want to say David's cat. Notice how, oops, yeah, suddenly now we got an error, unresolved reference cat. You'd have to put that inside of double quotes. That way it doesn't process the single quote. So if we run this again, you should see David's cat. So that's really all you need to know when it comes to that. My personal style is I typically do double quotes. You can change it however you want. So what happens if we want to print out a variable? Well, you may have already guessed. The reason why I use PyCharm here is it has this thing called IntelliSense. You see this little pop-up that keeps appearing? That tells you basic structure of what it's expecting. You see print, object, separator, and file flush. While I won't really get into that in this tutorial, you just know that what it's expecting is some object. Everything in Python is an object-oriented language. So we're going to say first, which is the name of this variable up here, print a variable. And you see there's Brian, our variable. Now what happens if you want to print more than one variable at a time? We'll say print, and you can say, oops, first, plus, and plus, last. You can do that. And a lot of people do that exact same way, and you see there's my name, Brian Carons. But there's an easier and a more correct way, string formatting. And what you're going to do is a little bit of voodoo magic here, but we'll explain this as we go. We'll say print, and you're just going to do your quotes. And you're going to say, my name is, and you're going to do a percent sign. And an S, which represents a string, I am percent D for decimal, years old. Now I'm going to save this and run it just to show you what happens. It says my name is percent S, I am percent D, years old. That makes no sense. What it's expecting is these are just placeholders. And that's the format symbol, or actually the percent symbol, saying it's expecting a string, it's expecting a decimal. A string is just an assembly of characters, like my name is a string, a decimal is a number. It could also be called an integer, a floating point processor, et cetera, et cetera. But basically it's expecting a decimal number. Now we need to do the percent sign to tell it it's expecting a format. And we will need to give it what's called a tuple, which we'll explain that in a future tutorial. There's like I said a little bit of black magic going on here. We'll say Brian, Karen's, and 40. Run that, and you see, oh, what is this? Traceback most recent call, line 21, let's right click here and get some line numbers. So line 21, if you actually click that link, it'll take you right to the line. A number is required, not str. That's what's going on. This is an error, and I want to kind of walk you through this, because when you're sitting at home and you're typing away on this, you'll make errors and mistakes, and it won't line up with the video, and you're going to go, well, what I do different? I kind of wanted to explain this. Traceback, that basically means it's going to trace back in the code. The file is the file we're actually running. The line is the line number, line 21. And if your cursor's up here in PyCharm, you can actually click it, and it'll take you directly to the line. And it'll say in module, module something we haven't covered yet, and it gives you the actual code, print, blah, blah, blah, blah, blah, the type error, percent D format. So we're looking at this guy right here, percent D, is a number required, a number is required, not a string. So what is really expecting is a number, now suddenly it runs. My name is Brian, I'm 40 years old. Little mischievous on my part. I apologize if that was a little bit confusing, but I want to get you used to making mistakes. Part of learning is making mistakes and fixing them. People get very frustrated when they make a mistake. I want you to make mistakes. All right, so let's explain this code and let's really understand what this thing's doing. We have a string, just a collection of characters, and inside that string we have some special things going on here. We have these formatting characters, the percent S and the percent D, meaning it's expecting a string and a number. Then we have the percent sign saying, hey, we are formatting this string, so it's going to look for the percent signs. And we're handing it a tuple, which is a list basically, or an array if you're used to other languages, which is think of it like a collection of objects. It can be numbers, letters, other objects, things of that nature. And we've got two of them in there, Brian and age. Now we can actually substitute that with, you guessed it, variables, first and age. These are the variables that we declared up here, first and age. Let's run that again, and you'll see, sure enough. And we can even modify this again, so we've got first, last, and age is what we're passing to this. My name is Brian Cairns. I am 40 years old. Whew, that's a mouthful there. So that in all its glory is string formatting and how to create and hopefully resolve and fix an error message. A lot of this is pretty intuitive, but let's say you just kind of goof something up, like let's add a little, you know, something there. You'll see the little red squiggly, and maybe that's not the best one. Let's just add some garbage in there, yeah. You'll see the red squiggly. So a lot of time you can just mouse over, and it will tell you what's going on, and resolve reference to, and you can click on little more, and it gives you a detailed explanation. That's part of why I chose this IDE, because I see a lot of people learning Python struggling with the built-in idle, and it's really not meant for beginners. I'm sorry. It's just not. All right, so we've made a variable. We printed the variable, and we've shown different ways of printing it. One thing we really haven't covered is string processing, which we're going to do in the next tutorial. What do I mean by string processing? I want to cover this in this tutorial, because I want to solidify what we just learned about variables. A variable is something that will change. Python's an object-oriented language. You hear that a lot, but what does it really mean? Well, an object is an instance of something, meaning it's a variable. Everything in Python goes down to what's called an object, or a base object. If you've learned Java, you're familiar with this concept. Just think of object as a widget. It's just this thing that exists, and everything grows upon that. The variable's an object. You're an object. Your cat's an object. Your dog's an object. Your computer's an object. Everything's an object at some point. With objects, you can actually manipulate those objects and change them, and that's what we're going to do in the next tutorial, string processing. I hope you found this educational and entertaining. Please visit my website for the source code to this and all other tutorials. It's voidrealms.com. I can't stress it enough. Join the Voidrealms Facebook group. There's like 200 of us in there. It's a lot faster and easier to ask 200 people for help than to email me and wait months, years, decades, centuries for me to respond.