 First, I want to talk about just the syntax for Python. So again, Python is a beautiful language. So here's the first rule for Python. When you write Python code, you must always begin at column one. You cannot just turn the door over here. You put a equal to a one like that. It doesn't work. It's a rule that all your code, your first line of code, must start at the column one. So it's a column-based language. So you must start from column one. The only option or the only available option that you can start anywhere else is the comment. So comment, you can start anywhere. It doesn't even matter. Python will just ignore that comment so it doesn't execute that quote. But your first line of code must start at the first column. So this is a code block in Python. And Python is also case sensitive. If I do that, both of those are completely separate variables. This is called a variable or actually called an identifier. A variable is a very generic term for all of these. So a and a here, we call it the pet is cat, like those. So all of these are called variables. And the actual name of the variable is the identifier. So therefore, they must be unique. You cannot have duplicate variables. If you do something like this, it's like, hey, at least you can't have two duplicates. Well, actually, you can't. What I did was basically I'm overwriting this value here with a g now as opposed to it one. So it's duplicating, but at the same time, so whatever we had before is now lost. Because Python is a dynamically typed language. Remember, we showed the level last time. So identifier is unique. And your variables must always begin with a letter or underscore like this. And then there you cannot use white space in between. So you cannot do like my pet is dog like that. So white spaces are not allowed anywhere in your variable identifier. You can use an underscore like that. If you want to use two words and your variable, my pet, so that you can distinguish between the two, sometimes called the snake case, something called the kebab case, I think it's called snake case. And you can do that. Or you can also use what's called the camel case. You lowercase the first letter of the first word. And if you have multiple words in your variable identifier, you uppercase it like this. My pet is cute. And then you put true, for example. So you can use underscore or uppercase each letter of each word if your identifier is really long. As opposed to my pet is cute. It's really hard to read. That's all. Again, readability. Yeah, so the rules is pretty simple. You cannot use any other punctuation marks either. So I can't put like A and B is C, right? This is not allowed. You must begin with the letter underscore and then in between will be letters or characters or underscore or numbers. It's fine. You can put numbers in here like A1, B, it's okay. But you cannot start with one like that. Okay, so very, very simple rule, I think. Okay, so again, everything here, as you can see, I must start on the left column. I cannot suddenly say, you know what? I want to put this over here like that. You can't. Again, the rule of Python, right? Everything must start from the left column. The only time that you are allowed to indent your code over here is if you have a different code block, a different structure in your code will load this later. Like if you want to branch something to a different branch using like the if and else clause, or if you have a function in that case, then you can branch it and indent your code. For example, if I say, if it's true, then you put a column here and then now you have to indent your code, right? And now it allows you to do that. I mean, you don't have to, I should say, but that's the only time where you can indent your code. If somewhere in your code you have a column, it will load this much later in the course. And so as you can see, I can do that. And then if that is true, then I go to this code block. Now this is a block of code. We have the indentation here. The indentation here, it should matter. They require just one space over here. They must be in the same column again. I cannot just suddenly, okay, I want that to be one space and then that is two spaces, right? Again, the rule of play that is beautiful. It forces you to write nice clean code, okay? And in Java, it doesn't matter. I can do this in Java. It doesn't matter. I can do that. I can even do this. It doesn't matter in Java. So that's why it's ugly in that sense, right? It can get really confusing, but I mean, who code like that? We don't, but we're just saying that you can. So the minimum space is one blank space, okay? Before you start the next one, or usually by default, this ID will give you at least like, I think like four spaces and four is pretty good. It's pretty standard. So if you keep typing, it would end in there for you automatically. So it would give you self plenty of spaces. So it's easy to read. So I can do that. Now I'm inside this branch and then from here on, I have to keep going, right? For example, if I do it true again, and then now I do another branch, right? And then I can do it again if false. And then it goes to a different branch and then I keep going, okay? So this is called nested. I'm nesting this if inside another, if inside another. So you can see it's like three layers down. We go deeper and deeper into that code. And so everything has to be like tripled back. You go inside here, you have to come back up. So that's why I wanted to send a Python one is, flat is better than nested, okay? If you can make it as flat as possible, it's very easy to read. So if you have your code that looks like this later on, if it looks something like this, if your code start to look like this, that means your code is too nested and you want to break it and make it into as flat as possible, because it'd be very, very hard to debug later. And you will see as you code. So again, this will be one of the only times that you're allowed to start your indentation in a different column as opposed to the first column. Okay, so some rules. Now semicolons. I remember someone asked last time, was it sure or forgot who it was? Yeah, you can use semicolon if you want a Python. It's not required. I believe you could do like that if you want to. I think that should be fine. Although it's not very common in Python because it's very distracting. And so usually you will see that my code, as well as the one in the books, we don't really use semicolon in Python. The only time that you might want to use semicolon is if you do this, if I do like a is equal to three, and if I want to put b is equal to four like that. So you can create variables and separate lines. If you want to put them together in a single line like this, as you can see, it's not allowed. So you have to do it. You have to then resort to using the semicolon that lets you do that. Okay. So that's the only time that you will probably see a semicolon being used in Python. Otherwise, we don't want to use semicolon. So you can put two variables on one line. Yeah. Yes. And in terms of the way we interpret that, if you're from semicolon, this must be a separate statement. Yeah. That just means if you want to type in the variables that were over, then put them together. Yeah. Right. Yeah. So I mean, semicolon do this. I mean, I don't really like to do that. I mean, it makes your code, I guess, shorter. Right. But I don't know. Is that easier to read or is it easier to read? Right. So, but Python is really cool because if you have like a is equal to three and I have b is equal to three and c is equal to three. I have three variables have the same values. Right. Initially, we call this the initialization. So I'm seeding these three variables with a default value of three. Okay. I can do that. Or you can also do this. A equal b equal c equal three. Okay. And now they're all assigned with the value of three as opposed to doing one separate line like that. So if you run a case where you have a couple of variables have the same value to start with, you can actually just do this. I mean, I wouldn't say that's a best practice, but it's doable. And comments, I already showed you that. Right. So in Python, you can use the pound sign for commenting your code. And I highly recommend you do that as well. For example, if I do, let's say in my code, if I in my code, I do this a is three and then current a. Right. Maybe when you write your code as you code, because you're the owner of your program, you know what a means, but I don't know what a is. Right. So what is a? Is it just any arbitrary variable? Does it have meaning? If it doesn't meaning, I guess it's okay. But what is a? So maybe in this case, if you happen to just happen to use a, then it's wise to explain what a is. Okay. You can do right above here like this, but the pound sign says a is our age. Right. Represent age or a is the value of something. So you know, so that matches you, but other coders will know as well. And so I recommend that you comment your code either right above it. Some people like to do right next to like this. That's okay too. But don't overdo it. So don't comment every single line. Okay. That's too much. You always do that. You make it really, really hard to read. You only comment when you need to explain a variable, explain a function, explain a piece of code that is doing something that, so that you remember later on, let's say six months down the road, you come back and look at your code and say, what is this thing doing? So you don't have to spend additional hour X, you know, trying to know what that means. Okay. So instead of doing this way, because you know, the more comments you have in your code, the bigger your file is, right? Every character takes one bite. So imagine you might have, you know, 10 lines of code, but your file size is like, you know, 30K. Why do you need that many characters in here? Well, because you're doing too much commenting, right? So instead of doing this way, to avoid writing this comment, what if I put my variable age? Now, if I do that, I don't need to put a comment anymore. It's understood, right? Maybe the only thing you want to put comment is, okay, age. Okay, I understand, but age of what? Right? That's the next thing. Is it age? Is it my age? My pet? My tree? What? And so again, okay, put, you know, age of, I don't know, cat. Right? So now you know exactly what that means. And so therefore, you don't have to do any commenting because as a coder, I, okay, I know what that is. Okay? So again, another rule two, naming your identifiers. Make them as meaningful as possible. I know it's a lot of typing, you know, but, you know, that is better than trying to figure out what age is. Okay? So make use meaningful names for your identifiers. And also follow the convention. Either you're doing this way, we can do age of cat like this. Okay? Either one, whatever is suitable to you, but don't do this. Okay? Because this is really hard to read. I mean, it'll work, but it's just really hard to read. Okay? And also don't do this. Right? I don't know what that is. Right? Unless the acronyms mean something else, it's okay. But otherwise spell out the whole word. Okay? I see, you know, students do like fruit, FRT, you know, like that is apple. You know, that versus this, you know, what's wrong with doing that? Right? Okay, a few chapters makes your code much more readable. Again, readability is really important in coding, not just Python, any language that you'll learn. Okay? So highly recommend. Okay? What I showed you here are how you can choose variable names. Also, we talk about a little bit about strings. So comment can use a pound sign like this. And you can also comment using the pair of three single posts like this. You put your comments inside here. It's very common in Python as well. This is called the multi-line comment. So comment can use a pound sign like this. Python as well. This is called the multi-line comment. Multi-line comment. You can do that, or you can also use the triple double posts. It doesn't matter which one. Both of these are same thing. Okay? This is a real comment. This is a comment, but because Python doesn't give you the multi-line, so a lot of developers in the program are you resort to using this type. This is actually a string. Okay? It's a string similar to this right here. I could do something like this. I could say line is equal. And then I have, you know, multi-line string. Because I could do that. It's the same thing as a single line string. Okay? So you can use triple posts or a single call or a single double. I mean double calls, it doesn't matter. Okay? Okay, so this is a comment. Because we're not assigning to any variable, then Python will still parse it, but it doesn't print anything out. Okay? So that's what it used for. Now down here are two strings. I can use, you can use a single call or double call. It doesn't matter. Python can take both. Whichever is your favorite, go for it. Okay? So that's up to you. And strings, you always wrap with the quotes. If you don't wrap with the quotes, if you happen to say g is equal to frt, okay? Then if you don't put a quote over here, or if you put like, let's just say, cherry. Then what you see here is that cherry is actually a variable name. It's another variable that has been created above. And you want to copy or use its value assigned to the variable g. So in this case, it's an error because you'll say, hey, there's no cherry created before. Okay? So just something that you want to watch out for. But these IDs will tell you if it's an error. So it's good to have these type of IDs. Well, outside comment, wrap text, because the next line can run out to the right. I think that depends on the ID and depends on how you set it up. I think we turned that on last time, right? So if you don't, in the tool, I think if you go to preferences, tool preferences, and there should be a checkbox somewhere, maybe inside the editor, see if you can find it. Yeah, the editor right here. So again, tools, preferences, editor, and right. So this ID, I did not check this box. Seriously, wrap lines. Okay. If you don't check this box, you're going to see that if I type a lot of comments, is it Stephen or Stefan? It's Stephen. Okay. Mention if I do this, you're going to see that it's going to scroll all the way to the right. Right. So we don't want that because it's really hard to scroll back and forth. So what you do is you turn that wrap on. So again, preferences, and go to editor and turn that on. So the next time when you apply it, and then now your code, your comment is now wrapped for you. So you don't have to scroll back and right. It's an ID thing. However, if you were to write an actual code, then if you expand this screen over here, you're going to see this vertical gray line here. Okay. This is like the margin of your page or your code. It's like the 80th position, 80th margin, like you write your paper. So if you write your code or something, your string or comment is usually, you would stop at this margin here. If my code is really long like that, then it's a best practice to terminate your line there and start a new comment like this. Okay. It's just the standard way to do code. So you'll want to have a really long string, a paragraph that extends to the end of whatever. So it's nice to do that because some programs like you mentioned do not have this wrap feature. So if you don't have it, it's really hard to do that. So the 80th column is the preferred position to wrap your code explicitly. All right. So I got that one. What else? Comments. Okay. We got the comments done. Just let's see. I want to make sure I cover. Okay. And then errors. We're going to cover the error very briefly because you will encounter this as you go a lot. Okay. So error is this ID tells you right away the first line of defense, I guess, is this ID, he will tell you every time you see a red X on the left column, it's an error in your code. I do that. You've happened to put something like that here. Okay. You see the first occurrence of that code. Okay. It doesn't give you all at once. Right. Again, why is that? Because it's an interpreter language. It executes line by line. So if you don't fix this line here, you're not going to be able to execute the rest of your code. It will stop execution at that point and your program comes to a halt. Okay. So okay. Good. I look at that. You must over that tells you it's invalid syntax. Right. So sometimes it's meaningful. Sometimes it's not because that's all you can tell you. It's valid and you have to know what it is in this case. So if I remove that and then it will then encounter the next error again, another syntax. So you fix that over here and then again down here, another error because it says I don't have cherry defined. So therefore I have to go up here and define cherry is equal to something. Okay. Put a string, for example, like that. And then now everything is good. Once it's all good, you shouldn't have any red axis and the left column. And so you're assuming that everything looks good. So now if you save your file and then you run your file, run it. And the first time you run is going to give it this little window here. Just, just say execute the current console is fine. There should be one that says don't show this again right at the bottom here. So it doesn't have to ask you every time. Okay. So if you run this, if there's no error, then if you have any variables that you created here and the global space here will be added to the variable explorer window on the top right, top right panel. And then your output will be in the console down here in the bottom right. Okay. The console is console 1A. You can have many consoles if you want. So it will tell you, okay, it runs the file at this location and at this directory. And then the output here, if there's no output, you will see a blank space between the cell number one and cell number three. If there's any output, then you will see right between here. Because I did not echo any output here, then, you know, all these are, they run the code and these variables exist in RAM and memory here in RAM only with this IDE. Not in the computer, not the program, of course. So we can interact with these variables because IDE here is a really great tool for learning. Okay. So everything looks good and there are no errors. Okay. So there are three types of errors in programming. And the easiest one is the syntax error, where I just showed you earlier, right? It catches the syntax error first. The IDE helps you to do that. If you run, having to use an IDE does not give you the syntax error. For example, let's say if you don't have an error, if you don't have this option here, if you try to run your code, okay, the program will tell you that, hey, there is an error on this file, line seven. Okay, line seven, it knows where it is right here. And the error is at least all here. And it's suggesting that this is a syntax error. Okay. So all languages follow certain syntax. Certain rules just like how you write your sentences in English, right? Has a syntax. And your code must conform to those syntax, those rules. If you don't do that, it's not going to work. It's not going to run. So syntax errors are really easy to actually fix and find. Okay. So syntax is, you just have to follow the rule of the language. The other type of error is a little bit more complicated. It's called the run time errors. It happens when you run the program. So if there's no syntax error, that's fine. Let's say I go down here and do another program. Let's say if I put like some, it's equal to, you know, example, a classic is both like a division of zero, right? Put 10 divided by zero. Okay. As you can see, it's not a syntax error, right? It doesn't give you that error. So the idea is to know that. But when you run the program, only at run time, it will capture that it will catch an error and say, hey, division of zero is not allowed in Python. Okay. So that is a run time error. Another error you have to fix. It will tell you again where it is, line nine, at this line code here and give you the error here. So you can fix it. This is a run time error. It's a type of error, also known as exception error. We will learn this much later in the course. It's an exception that allows you to catch those type of error you can fix in the program. Okay. As there are some other run time errors that are completed out of your hands. Like it uses a lot of resources, system resources. For example, if your data or your code has leaks, memory leaks, right? And you don't know that. Some of it is leaking memory. When we say maybe leakage, we are referring to a piece of code that is executing some code in the background and uses memory in the background. Like for example, we have an infinite loop. That loops forever. If it does that, it will use all the memories of your computer and your program will crash. Sometimes it forces you to reboot your computer. So that is another type of error that is completed out of your control. And as a programmer, you have to avoid that. It will learn errors much later. So those are the two types. The syntax and the run time error. And then there's another type of error that also occurs during the run time. And that is the logic error. This type of error is the most complicated type of error in the most consuming time you will spend in finding logic errors. Logic errors is when you do something like this, right? And print is, let's just say put my total is, I mean, I'm sorry, total. I do that. And, okay, I got 10.0, which is fine. But I guess the logic is like, you know, maybe I'll do the example I mentioned. I remember it in the book, something like this, but like a message is equal to hello Python. Like that, for example, the print message. Okay. Run. Right. No errors. Everything runs great. And the only error you see is the misspelling of the word Python. Okay. So that is a logic error. Because everything runs great. It's just that it's wrong. The way I have it, the output is wrong. You have incorrect calculation. Like one of the assumptions we're doing is calculate the weekly pay for employees. And you're going to see that sometimes you have the wrong calculation. The output is not right. I put the correct data, but it's coming out wrong. And so you have to go into your code to find that logic error. It doesn't give you any clue. You have to trace your code, find it. Where is this message being printed? Well, this is a really simple one. So I know that the only time I print is print 922. But then the error is not here because if I see, if I see this right in here, then yeah, I can fix it right there. But I don't get that, right? So maybe in your code somewhere, right way above or right in between somewhere, I have the message variable somewhere in my code. Has the value Python and I find that location to fix it. So you can see that if your code is really convoluted, it has very deep nesting in your code. It's really hard to debug your code. So this is a type of error that is the most complicated or most complex to debug is the output or if you have a wrong calculation in your program. And those are the three types. And you will counter this throughout the course as you type code and write code. All right. So yeah, those are some of the syntax in Python and the errors that you encounter. So now I want to, let's see if I have, I look my notes and make sure I cover some things you've jumped into data types. Okay. Yeah. So that's fine. Are we about a couple minutes? Okay. So the next thing I want to cover is, yeah, before we write code is understanding how to construct your program. Okay. Now, remember that when you write a program in Python or it doesn't matter what language, a program is a sequence of instructions, right, that occur in order. You have to be in exact order. If you miss capital or if you miss one or a couple of steps, you might have it wrong output and correct solution. And so it's like writing a recipe to cook some food, right? Writing a recipe, I guess, it's doable because if you were to think of a recipe, you can add salt later or before, it doesn't matter, I guess, what tastes, right? But in Python, sometimes that doesn't work, right? You have to get the data first. But one thing is that I can get age first before I get ID, right? Maybe it doesn't matter which one occurs first. It doesn't matter in this step. It depends on whether you want to process age first or ID first, then that order becomes important. If I process both at the same time after that, then it doesn't really matter, right? So going back to what I talked about last time, where you start writing your assignments, doing your assignments, think about this simple process. Again, the input, okay? Process, output, why the policy IPO? Hit stocks, right? This is how the computer or the program reads or process, executes. The program always needs input in order to process something and then it should output something, provide some kind of feedback, okay? Always go back to this very basic concept. I will say it again and again in the future, okay? As you get more and more into some more complex programs. Now, that is the, that's how the computer process it before development, okay? Development is meant you would do this. You would do the output first, design the output, get the input and then process. So a little bit different, the thought process is a little bit different. So again, going back to how you build a house or build a car or whatever, right? You always want to design the output. What is it that you want to achieve? What is it when you want to get first? You have to know the output first before you start doing the input and get the process, the other process. But a very simple program, you will see that you can think right in your head very easily what you want already. So you can just start coding and that's fine. But as you get, if you get a little bit deeper into some more complex programs, this process becomes extremely helpful and useful, okay? So for example, we do one really simple example here. I want to calculate the average of some test scores, right? So let's say I want to calculate the average of five test scores. And if I were to give you that question, the average of five test scores, how would you do that? How would you write a Python program to calculate the average of test scores? And what do you... So in this case, what is the output, right? What do you need here to get this thing to work? So the output, yeah, the output, right? Yeah, so the output, what do you want the output to be? The result of what? The result of the test scores and average. We are right, right? So you want the average of the test scores, okay? So you want the average, the average here. Okay, so that is my goal. The end goal is to get the average of the test scores. Am I interested in printing the test scores? Yeah, it's up to you. It depends on whether they want to show or not, right? The output, it doesn't matter. In this case, I just want the average of the test scores. Okay, so that's the end goal. Now, how do I get this to work? So now we go to the input, right? So what type of, so what do we need for input? The score, right? We're going to need five scores, yeah. So you put like 100, you put a 90, and then 89, and then 95, and then maybe this one here is 70. We got, so that's your input, okay? And then finally, okay, once I got input, then I can go ahead and do my process. So what is the process? Yeah. So sum all of those and then you write it by five, right? So you do some, some of the scores and then you write it by five. So you can see that this is what you want. If you don't know what you want, you don't know how to process your data. If you know exactly what you want, okay, fine, I need the averages. Well, average, I need some input data. Okay, now I got my data. How do I get the average? And then again, math, right? It's always math involved. A lot of math involved here and you would do that, okay? So that is the way of thinking. And then when you code, you wouldn't follow this process here. Okay, I want the input. So you would start here, okay? So you would start, this is the coding here. So I need the input first, okay? So for example, I'm just going to add the input here. Simply here, like, you know, S1 for now is 100. Right? I'll put in some code so you can see better. S2 is, you know, 90, S3 is 89, oops. And then S4 is 95 and S5 is 70, okay? So those are my test scores, my input. Very simple. And then now my process, right, process is I need to add them up and divide it by five. But then I need to assign that to a storage. So I can print it out. So for ABG, right? Yeah, so we do this simple, okay? So it'll be, so like S1 plus S2 plus S3 plus S4 plus S5, and then you divide that by five. Okay, so this is what we do. We had the example earlier about the math. Well, this would be correct. Now why? Because it's supposed to be S5, we need an R5. Okay, right? So the rule of precedence, the math, right? We showed you earlier, it's the pandas, right? parentheses first, right? And then exponent, if there's an exponent, and then multiplication or division, and then additional subtraction, okay? So in this case, because all these are pluses, all of these will occur first if there's only those, but then we have the division. So this one takes precedence. So therefore, like you said, this will actually occur first. If you do that first, you're going to get a wrong R5, right? So we want to add these first to the fourth. Again, the math is the pandas. For parentheses, exponent, multiplication, division, add subtraction, so the least precedence. So therefore, I want to make sure that these five values are calculated first. So I get a total of the sum, like you mentioned. You can do that separate step, it's five too. Sum is equal to that. And then average should be sum divided by five, right? So this is the process. So we've got the process, and then finally we do the output. Okay. And in this example here, we just use the print function, and I'll go over the print function after we take the break. We'll come back from break. So we'll put here AVG as the output. And then now, if it's all correct, you run it, you're going to get the average of 88.8, right? So very simple calculator, but you can see the logic is also really important as well. How do you do it? How do you get the data? I mean, the data is okay. Data are just raw data. So it's like an database, right? How do you use it? How do you put together to create general information is important? Once you have the information, then you get knowledge from that, right? So the process is always going to be this way, okay? I'm telling you again, I will say again in the future, as we get a little bit more complicated later on. Always think about the output, what you want first. Sometimes the output may be more than just the average. Okay, I want the average. I want their name, the username, the ID, the location, the address, right? All the pets, they own, all of a sudden the output. So then you need to gather the input in the material and then process it. So the most time-consuming part is of course in the process part, okay? Just like in the real world, you build a car or something, it's the most consuming time. But within the process itself, the most time you'll be spending after that is the debugging. You run to a lot of debug time because the output again will not be correct and you will go back and then, you know, write and fix your code over and over again until you get it right. Okay, okay, are there any questions before we take a break? All right, so let's take a time and a break. We'll come back about nine or five and we will continue with our discussion on the data types. So I see you back in 10 minutes. Okay, so let's take a look at how do we, how we actually write program. I did already, we did some really simple basic input process output here, okay? So again, when you create a variable, this is, we call these initialization. When you create a variable, it's usually you want to set it to store a certain value, whether it's an empty value or some type of value, as opposed to just something like hat and then you leave it like that, okay? So in Python, it doesn't allow you just to create a variable like that by itself. You have to assign a value to that. And I'll show you that the equal sign here is the assignment operator in Python, okay? So you have to assign something. And let me go ahead and just comment these out for now. I shouldn't want to create new files. We don't use that again down here. Okay, so the assignment operator is the equal sign, okay? And it's also the same operator when you compare two values for either they're equal or not. So if I do like pet equals, pet equals dog, I do that, right? I mean, pet equal dog is the same thing. But if you put like if pet equals dog, then you're really comparing the two, okay? If I do an if clause like that, okay? Then I'll compare is pet equals dog, get a value of dog. But if you just leave it along by themselves, then it's an assignment. If you use it after the if clause or the while clause or something we'll learn later, is now you are using the equal sign as a comparison operator. And someone will use a double equal sign to make a difference. In JavaScript, you actually have a three equal sign as well. But in Python, there's only one. So just make sure you have to confusion with the equal sign here. So you have to assign something. The value here will be a dog. If you don't know yet, you can leave it with a value called null. I mean, a none. It's a none is one of the data types or data that you can use. None is just means nothing, right? It's it's it's no, it's no in the languages. But Python is called a none, okay? So you can always set to that. And then later on, maybe you can use it so that when you get the name of a pet, you can assign later. So this is useful only if you want to put your variable. You want to create ahead of time so you can use it later in the code as opposed to creating a variable somewhere in the body of your code. It's really hard, again, to debug. But so your program, usually all your variables, you want to move them to the top of your program, okay? So that they're in the single place. And then your code will be below that. And then you can always refer to reference them. But as a code, you'll see that you as a code, you want to go back. You may not want to jump back to the top and then come back down again. So as you go, you can add a variable as you go. But at the end of the day, when you are done, we want to clean it up. Then maybe you want to go back and be moving, move all the variables to the top, to a single place. It's easier to find them as well. Okay, so that is the assignment. This is called initialization, right? You always want to initialize your variable, whether with a default value or with none. Okay, so if I want to create another variable called score, then usually you would default it to zero, right? You start with zero. And then after that, you will update it as you go. So a variable is, as you can see, a pet of scores of variables. The actual name, again, is identifier. So what is a variable? What is an identifier? Why do we use them in a PyTorway program? Anybody know? What? Initialization or likened utilization? Yeah, it's the type, but then, yeah, so what is a variable? Things that change, that can change. Yeah, right. It is to store some data that can change, right? Things that change, okay. So a variable, because again, we have very limited capacity to remember memory addresses in the pro and the computer, right? So a variable is actually a container way pointer that points to a location in memory, right? So if we like, zero x and zero zero five three, I mean, one zero one zero one somewhere in memory, we can't memorize those so that what they do is that the variable or identifier pet is actually a container that points to the memory address of that particular location so that we can use it again like some other variable. We can use it again like Steven and you were saying, we can use it again and again as opposed to keep going back to reference zeroes or ones and zeroes or ones, right? So it's a container that stores data like a bucket or a cup or whatever it is. So in Python, because data types in Python, it can be, I mean, variable in Python can store any types of data at any given time. So it's like a cup or a container that right now I might have water in the cup, I can pour it out, now I put candies in there, I can contain rocks. Whatever it is, can fit into the bucket, it will take it. Not true in Java, for example, Java is okay. I have this container and this container here only contain candies. You cannot put water in there, you cannot put anything in there out of the candies, right? That's the strictly typed languages. So in this example, I have two identifiers or two variables, pet and score, and they have two values and because they're values, they are changeable, right? The values can be changed to something else down the line. So at this point in time in line two, pet is now none, maybe sometimes after that, I change pet to something else. Whatever the condition is, maybe you just want to or maybe you can say, well, I will be assigned pet with the actual value if and or when only when the score is greater than zero, right? So if score is not zero, I mean it has to be or if it's positive but not zero, then go ahead and change pet from none to something else, okay? Otherwise, keep it at none, okay? And that is how we also use the flow chart to do that. I should give you assignment as well. If there are more people in line, then keep adding, keep calculating the agent, check the agent, and calculate the fee and whatever it is until there's no more people in line. So again, as if and else, we'll do that in the next chapter. Hey, so in this case, we have two variables called pet and score. And if you want to know what type of data they store, how do you know what type of data they store, the data type, is depending on the value assigned to those variables, okay? If you assign a none to the pet, and this will be a data type of like none, if you assign zero or any number to a score, then this will be of the type integer. It's the integer number, okay? If you put say points is equal to 1.5, then this is a float called a float number as floating points, any decimal values. So if Python is this float, this is the integer. Integer are whole values, okay? So decimal numbers are called float, and some languages, they have different names. They have like a, they have float, they have double, they have a decimal like in Java for example, but all in Python is really simple, just either integer or float, that's it. Decimal or whole number, okay? Now the type of, so okay, let's go some more, and we have here day is Wednesday. So this one here is string. I put a Wednesday course Thursday at 8, but it's Wednesday. So this is a type string, again, is referenced using the single float or a double float, doesn't matter, okay? A string can also be like this week, week two, okay? Number can be a string as well, even though it's a number, it is a string because you wrap it with a quote. If you take out the quotes, there is a number, it's an integer, but because it's an inside quote, this is also a string. It's an ASCII character. And then there is a type of Boolean called true or false, okay? Done, and then you have here completed, okay? So notice that the color changes to orange, and this ID tells you that there was a keywords, okay? Keywords, in Python, you cannot use those as variables. So I can't do this, true is equal to, okay? It's a keyword, it's not allowed. So these two are called Booleans, but the Boolean mathematician. So in Python, Boolean is either a true or false, not zero ones, not a yes or no. It's exactly true or false, and it's case sensitive, has to be capital T or capital F for false, okay? That is the syntax of the book of Python. I think it's the only language that I know of uses capital T and F. Most languages use all of our case, okay? So that's the Boolean type. And yeah, so if I miss, they're probably more, but if you don't know what type they are, so for now, you can, let's run this. Let me clear my list over here, okay? If you, so notice if I keep running, let's go. Yeah, if I run it now, I just keep adding. Well, don't show this, okay? Okay, you see that it keeps adding variable to my list here, and it grows really big. I don't want that, all right? So you can clear it by clicking this little trash can here, like that, and it's gonna ask you yes or no. Don't show again, just say yes. So clear my RAM and memory, because I want to just show this data here. So you run that again, and it will tell you up here, I don't know if I can zoom this in or not. Yeah, can zoom in. So it will tell you the completed is a type bool for boolean. Okay, the same thing with done is also boolean. We have a day, and the week as string, STR is the string, the actual type, and Python, it's just short or string, and then the score is an int because it has no decimal value. The point is a float, and then we have none as the none type. Okay, so these are the very primitive type of data, and a variable of the primitive type can only contain or store one value at a time. You cannot have like score contains zero and 1.5, only one value at a time, and that's very primitive. But of course, you can always reassign them with the values as you go. Any type of value, it doesn't really matter in Python because it's the nature of the language. So we have to be extremely careful when you do any calculations. So for example, if I do a total is equal to, if I do points, you write it by week. If we use a string, so if I try to do that, you're going to have, again, it's an error. It's not syntax error, it's a runtime error because you cannot divide a number by a string. So if this is where a number, then yeah, that's fine. So that's okay, you get a result. I didn't print it out by the total if you see, is 0.75. So that's why it's really tricky in Python because I might change it to something else after that. And then you do a calculation, you get a wrong output and so forth. So be careful when you do this type of operations, especially math operations. Now, the next thing is, so these are the primitive types. Now I wanted to go ahead and talk about the print function. It's just the most widely used function you will use in program, if I done, to print results. It's called print. Exactly, that's what it means. If you mouse over this again, if I do it again, print, if you type that, you will have a little pop a window. I can't see it, let me close it down here. Let's do it again. Print, print, okay. So it tells you here the syntax or the actual implementation of this print function. As you can see, there's a lot. Print followed by parentheses here ends over here. And in between, a bunch of other stuff. Followed by, you separate by a comma here. So the first position in this function has a parameter called values, plural, it's of type object. The next one here is called the sep-s-e-p for a separator. And a separator is of type of string or any character. And then you have the next one you call the end. And the end is also a string. And then you have file and I'll type some string as well. And you have flush and so forth. And at the outside of this parentheses, you have the arrow pointing to something called none. So in this case, this function print accept some values. And the dot, dot, dot comma here means that you can print as many values as you want if you separate each with the comma. And then these are all optional over here. These are, even though they're there, you don't have to use them. But there are some default values assigned to those already. So by default, if you print something, it will include in there already. And the arrow outside here pointing to none, it just means that this function print does not return any data back. Well, the function later, that function either returned data or it doesn't return anything back. So this one here returns nothing. You just print something out to the screen. So it does it in a very passive way. So that means that the first thing I want to do is I can print one, two, three. And if I want to print more, I can put here another set of numbers. Doesn't matter. I can print a string, ABC. I can print one of the variables done. So you can see I could print four things or n things here, or if I separate each with the comma. So if I were to go ahead and run this line again, and the output over here, I'm going to see, I'm going to clear this console, right? Click and clear, or you can do control L, I think, yeah. And we'll see the print function will print these four things. One, two, three, 90, 90, ABC and true. Okay. So when you print data from the program out to the console output, the result out here is that the output will always be a text, the string, because that's how it works. Not just Python, all languages are like that. Okay. So even though one, two, three and 90, 90 are numeric in the program, and even done is a true value Boolean, the output here is going to be just text. Okay. So everything you print always has to convert it to text. So it does it implicitly, those terms we talked about earlier, explicitly or implicitly. In this case, Python knows that one, two, three is a number, but it will implicitly convert it to a string before it can print it to the console. Same thing will be done here as well. Okay. However, if you do something like this, you print, let's say string, my cat is, my cat, well, my cat, my cat of, let's see, my favorite pet is, and I put here, for example, I put here, now I want to do something different. My favorite number is, and then you put here like 10, right? Something like that. Oops, sorry, wrong, wrong quote, that's a wrong quote. Okay. So my favorite number is 10. You print it, you run, you see that my friend number is 10. Okay. So that's okay because this is a string, and this is a number who will convert that automatically. Now, sometimes you want to print something like this. My number is 10 as opposed to my number is plus 10. Okay. So in this case, the plus here is not a mathematical operation in this case because I'm doing, in addition, a string against a width and number. So when you do this type of operation with the math plus symbol, this is what now is being used as a concatenator. You're joining two strings together, and both have to be string. Okay. So if I were to do that, I see if you've got there any error or not, you're going to see that again, syntax is correct. There's no error there, but logically when you run it, you have an error. It says it can only concatenate string, not int to another string. So I'm trying to join a number to a string because the output from the print function is always going to be string. So therefore, in this case, Python does not know how to explicitly or implicitly convert this because it does not know. Do you want this to be a string and combine together, or do you want this to be a mathematical operation? You want to add those two together. Which one do you want? Python cannot discern from that. So you have to explicitly convert this to a string if you want it to be string. So in this case, you have to wrap this number 10 with inside a special function called string of the type string here, this type here, str, like that. So I'm explicitly converting my number 10 to a string first, and then I will use the plus sign to join them together. And now both are strings. So therefore, they are OK. And then Python is happy, and you print it out, and you get a result here, but there's a problem. Right? That's a space and issue. What if you just wrap the table of quotes? They will double quotes, and it will be the same quote. Yeah, if you do like that, is that good? Yeah. Will that work, do you think? I think it will work very well. Yeah, right. I put my bet on you. Yes, so that is a string already, right? So yeah, Python, no. OK, so two strings, sure. Go ahead, join them. OK, so if it's string already, you don't have to do this again. You don't have to convert again because, I mean, you can if you want to, but it's no need to. It's redundant. It will convert a string to a string again, so that's still be fine. But yeah. But what if you have, for example, a point, right? If I put points here, I put points like this. I know just some numbers, but if I do that, right? So in this case, you have to explicitly convert it, right? You can put a cost around it. If you put a cost around it, it's a string, the string points, as opposed to the actual value stored by points, which is 1.5. OK, so this case, you have to explicitly convert the points to a string first, which is 1.5. Convert to strings that will look like this in memory with a quote around it and then join it together and then you get your result printed down here, 1.5. OK, so that is the only time you have to do that. When you're using the plus or the operator to join strings this way. OK, however, if you do it this way, using a commas operator, each of those things, I don't need to do that because each of those variables or values will be treated differently or separately by itself. So Python will convert that automatically for you. OK, the only thing is that in this case, so notice up here, I did not put any white space in between. Right, just comma, comma, when you print it out, it provides a white space in between four main for every one of those, except this part here, this line is one piece and then plus the points, but there's no white space in between here and looks ugly. OK, so you have to fix that. And you can do that by putting a white space here. So you preserve that white space, right? So it looks nicer like that. Or you can do this plus and then a white space and then plus that, right? You can do that too, right? It is an extra character and then you print it out and get the same output. Because again, the output is really important for customers, right, for the user. The code is your responsibility to go and do all of this stuff just to make sure everything looks nice so the user will buy your program, right? A lot of work and you have to do that. And then OK, so white space again, this is OK, but the better way is to put here space is equal to that character and then here plus space. OK, why is that? This is the power of variables. I can replace this space with any character I want. What if I want to put like dash? I can just put it here and then I don't have to change my code down there at all, right? It's a placeholder that I can change. I can remove it, I can do whatever I want and use that for that purpose, OK? So that is the conversion, converting one type to another type, especially strings and numbers only, usually those two, and some type later on with little references. So you have to do that or you have to resort to using the comma. So instead of that, you can also do this. Put a comma here and then I don't need the space here and then my code looks fine because when you put a comma, every comma you put here will automatically generate a white space, OK? So that's why these are here. I mean, it's not the space that put between the commas here. This doesn't matter, OK? It's the comma that Python would know that this is a piece of data and then it will put a white space, the next one, white space, next one and so forth, automatically for you because of this function here. Here, if you do this way, it will add. If you don't include the comma, you put a plus sign and you have to explicitly add space by yourself, OK? And the reason why it does that is because, again, go back to the print function I showed you earlier, OK? One of these is called the SEP. You notice that by default, SAP is for separator. It's a separator. It's a white space between. It's a white space, OK? So if you want to remove the white space, then you have to include it in here. So, for example, we go back to this one here, make it a little bit nicer. And I want to remove all the white spaces, right? Like this all going together. Then in here, any one of these, after these values, I can go and put here SEP equals and then you make your own space. I can put two spaces. So now every comma will have two white spaces as opposed to one. OK? Or if you want to make it a little bit fancier, you know what? I want to separate each of those with the dashes like that. So you get that option to kind of make your alcoa look kind of nice, you know? So if you print like digits or numbers, you can do that. It will automatically add it for you there. If you want to remove the entire space completely, just set it to empty strength. This is called the empty strength. A pair of quotes without any space in between. It's empty strength. So therefore when you print it out, now it's all dumbled together, right? So no spaces, no separator. So therefore it's sometimes you want to do that. There are ways, there are certain situations you want to do that. OK, so that's a separator attribute or parameter you use to do that. And again, this is the empty strength. This is not the same as, so I move over here. If I do, you know, j is equal to the empty strength, you see that j is a strength, has zero characters, has no value. OK, as opposed to if put k is equal to none. So k is not empty strength. k is a tight none. It's not a string type. And so that's different. As opposed to if I put p is equal to a one space like this. OK, so p is a string as well. It's a string where it has one white space. It has one value, one byte. So make sure when you put an empty strength, you have to completely remove any white spaces between the quotes here. If you don't do that, the length of this p value is going to be one, as opposed to zero character. OK, and that is the next function I want to show you is the size of a particular character or a variable. So for example, space here. I have, I can put two dashes here. So how do I know how many characters space has? Is by, let me move it up here. Also, you can move lines in the code here. You can either highlight it and then, you know, I think you can drag it around if you can. Yeah, drag it around if you want to. Or you can just highlight the line of codes or lines of code you want. And you press the Alt key in the upper down arrow. You can move your line up and down like that. Sometimes it's faster to do this way. The copy and paste in coding. So I want to just, you know, I want to know the size of space. So if there's a function called length, length of central length, the length of the value that space contains. OK, so that will be, in this case, it'll be two, right? Well, I want to assign that to a variable. So I put here size is equal to length space of length. And then you want to print out size. And I'll comment this out for now. So we'll print that out. You see that my character size of space is two because it does tell me that space up here or here has size two. This one tells me, but how do you know it programmatically, right? So you have to use the function called length to give you the result of the number of characters it contains, which is two. So you know that inside this, so this space is now contained two characters. So the length function determines that for you. What if you don't, what if I just do this? I'm going to go up here and let me see if I do this. Something like this, OK, and I will show you, right? How do you know how many characters it's in there, right? So again, this function will tell you right away. So you know that, OK, it has 33 characters. So when you add, when you do, when you, this is actually useful when you read data from the input to the console. OK, so I show you the print function. And now how do you get data from the user? OK, the other function you want to use is called the input function. So let's put here input. And put it very simple. If you leave it blank like this, then it will still run. And in the console over here, it will just pause your program. So every time you put a print function, the screen will pause. And it will stop, it will continue until the user hits the enter key. OK, so if I do it now, you will see that I don't see the print function being printed yet because I'm still waiting at the input line 20. In this case, it hasn't shown me yet, but it is waiting for that line. As soon as I hit enter, then you go ahead and proceed with the next two statements and print that out. So the input function is where you ask the user to input some data. OK, so I want to ask and say enter, so I put a string here, enter your age. OK, however you want to display to the user, you put the message here as clear as possible so they know what to enter. OK, so once you do that, then the program Python will wait for the enter data to be entered. It reads it in and right after that, you want to also assign that input to a variable, we call it age. OK, so this age value is now, you know, can be changed or entered dynamically by the user as opposed to we have signed that locally in the program itself. So now I can say, let's print here, your age is, and then put a comma, age. OK, I'm not using this one here, so you read the input and then you get the input. I don't do any processing here because there's nothing to process, so you can skip the part and now it's waiting for the input here. So the cursor is blinking until you enter something, so I put here let's say 30, hit enter, and then I say your age is 30. OK, so when the age comes in, what if I enter something else besides 30? If I enter like a T, what do you think is going to happen? It's still saying your age is T, why is that? Yeah, it's a string. Yeah, so here's the other thing. Remember that I said when the print function prints everything out as text strings, it's true for incoming data as well. Every data you read from the input is always going to be string, whether it's a number or a character. I know that we're assuming age is a number, so I enter a number, so it knows that when it comes in, it actually comes in as a number. You will see that if I enter age, go up here again, if I enter like the 20, you see the age is a string, as opposed to the actual number. What if I want to add like five to age? So I got age, whatever the age is, and I want to add five to it. So you can say age, say new age like this is age plus five, and I print new age. So I do that now. My age is, let's say 20. I expect to get 25. But now you have a problem, right? Because back to the rule I mentioned earlier, I'm trying to do something like that. I'm trying to add a string, age comes in as a string, but I'm trying to add that to a number. So now Python doesn't know what to do with it again. So back to this case again, what do you want? It says, so do I want to do a string of five like that? So I get 20, and I get an age of 205. I draw two strings, or I want to get 25. Well, in this case, age is a string. So therefore you have to convert age to number. So you do the opposite direction by using the int function. You wrap that into the int function. So it converts the age from a string to an integer. So Python would know, okay, so you expect an integer plus an integer again, okay, you're going to get 25. And then now if you put 20, I'll get 25. So back to that possible logic error. If I happen to put a string for five, I'm going to get a really huge age. So that's the conversion. I convert it from a string to a number, so I can use my number for processing and I'll put it back. Okay, so every time you read data from the user console to your program, if you expect that input to be a number, you have to explicitly convert it to the type, whether it is a whole number or a float. So the type will give you that clue. The most ones you'll be using are just string, float, and these three are the ones you want to use quite a lot in the program to convert between the two. So if I change to a float, now I expect to get a decimal value. Without that, it's a whole number and you get without the decimal value. So you read input. If it's a number you expect in that, you must convert it. What if now I enter a T as opposed to a number? Well, you got another error, right? Because you cannot convert a letter T to a number T. String is okay. The other way around is fine. I can change a number five to a string of five, but you cannot convert characters to a number. So if that's the case, it's a problem that you have to fix and we'll do this later when we talk about casting also, validation and things like that. So you have to validate the input. If it's not the correct type, if it's not number, you have to keep asking the user, sorry, doesn't evaluate input, enter again, enter again until you get it right. So that's another thing I want to watch out for. So for our assignments, as you work on those, we'll assume that everything is correct. Well, I assume that you're going to enter a number, but then it's your job to make sure you convert it to the correct type due to any calculations. So very simple conversion here. So you see here, I'm using age here to get the input. Let's convert it back to and I use that to convert to a number. I add it and assign that to a new age. And that's okay in this case. If you want to do that, that's fine. If you plan to use age again in the future of your code, then you want to preserve it like this, right? You save it and then assign that result to another variable and use it that way. If you don't intend to use age again ever after that, then you can just go back and reassign it to age itself. And so therefore, you don't have to create another separate variable again. If you create another separate variable, it consumes another piece of memory in your computer. So a variable can be assigned to itself, right? Because you can treat it like a separate variable. And so in this case, it saves you memory. And also you don't have to have so many variables floating around in your program as well. All right, so input, and then what if I do something like enter age and I've got no one here. Maybe like what do you call a delta, right? Input multiplier, like that. Is that how you spell it? I think that, okay. And then now my age would be age plus delta. So again, both are numbers. So you have to convert like that, right? Okay, so I'm reading two inputs here. I'm reading two numbers. And the age would be let's just say 40, whatever it is, let's say five. Again, so I get 25. So you can have all sorts of input. So this is where you gather the input. If I know what I want, I'll put first and I get my input. So back to the test score, I will prompt the user five times to read those five test scores to be processed. So you do that five times. And when we get to the loop section, you'll see you can write it much shorter using loop. But for now, in this case, we will have to do it five times, enter score number one, enter score number two, and so forth. Okay, so yeah, I want to print this age. This is will be, in this case, be the output. I know that I'm going to print this age. And then the process is to add the age plus the delta. This is the processing. And then this is the input, right? So again, very simple input process output.