live- Python Tutorial

Akansha Yadav teaches Python basics from scratch, covering data types, arithmetic operators, variables, and common errors. She built a drug-vending machine in Python and uses live examples to show how the Python kernel works as a calculator, then moves into strings, comments, and the print function.
Chapters
Okay, let's begin with Python. What exactly Python is and how we can use Python. So in this particular notebook, I have mentioned everything related to the crash course of Python. So in— whenever we talk about programming languages, right? So programming languages are like very useful these days because using programming languages we can create so many things related to AI. If we are talking about healthcare machines, everything is created using the programming languages. When I started my career, I created one— one machine which was drug vending machine that was created using Python only. So there were so many components that we added and we programmed those, uh, systems with programming language, which is Python itself. So learning programming makes your career and also can boost your career. So let's start with Python. So in Python, when we say data types, right, so that it, it depends like how you are typing the— how you are giving input to the computer. Whenever we say we have to give input to the computer, then it means we are providing the values to the computer that computer can understand. We also have to take care what we humans can understand. So different programming languages are designed in such a way. So when it is data type, it means we are going to give the input data inputs in different types of data. Like it can be numbers, it can be decimal numbers, it can be whole numbers, natural numbers, it can be strings, it can be basically a text, a paragraph, a word file, anything it could be. So in Python also there are some specified inbuilt data type which you can use to provide input to the computer. So the number one data type is the numbers, which is like if I— if you are typing, typing 1 1, it is going to give you 2 because your Python kernel or your CMD can act as a calculator as well. So I have written 1 1, it means it's going to give you 2 because it is acting as a calculator. That particular kernel is acting as a calculator. So Python is a high-level language. When it— when I say high-level language, it means it is going to give you the brief, uh, thing within the language that you can understand. So 1 1, we can easily understand. But if I ask you that what language, which language exactly your computer can understand, that is zeros and ones. Computer can easily understand zeros and one, but we humans cannot understand zeros and one. If I'm going to write 010101 something, then you won't be able to understand what I have written so far., but your computer can easily identify what it is. Same way, you have to, like, in the case of numbers, you can directly write down the numbers, whether it is 3, 4, 10, 20, 30, 20 lakhs, 30 lakhs, anything it could be. So with the numbers, we— I am trying to use some operators to show you that this kernel can act as a calculator. When I have written plus, it means we can add two numbers and we will get the result. When we are writing multiplication, this is the symbol of multiplication. In computer, or you can say in Python. This is the symbol of division. This is exponent. When we say to the power of something, 2 to the power of 4, this is what we have written, 2 to the power of 4, and it's giving the output 16. Then comes modulo. Modulo is the interesting one because when we wanted to just get the remainder of anything after dividing two things, then you can get the modulo as an output. Modulo means you are going to get the remainder as in the output. When you want to just get the remainder, then go with the modulo operator. Modulo operator is the percentage symbol. I hope I am audible to everyone. Can you let me know in the chat if I'm audible to you all? Okay, so modulo means when you wanted to get the remainder, then you go with the modulo. So whenever you are writing 4 modulo 2, it means we are going to divide 4 by 2. So it means we are dividing 4 by 2 and we are going to get what remainder? In this case, we are going to get 0 remainder. If I say that you are going to divide 15 divided by 2 then in this case you are going to get remainder as 1. So whenever you wanted to check the remainder, you will go with the modulo operator. Modulo operator will help you get the remainder with the division. From the division, if you are looking only for the remainder, go with the modulo. If you want the complete division output, then you can go with this division symbol. When we are dividing 1 by 2, it means you are going to get 0.1, which is the half of 1. When you are just looking for the remainder, go with the modulo operator. Just like in this case, 5 divided by 2, where we are checking only the remainder, so we are getting 1 as an output. As I said, your kernel, your Python server, or you can say your CMD, can act as a calculator. It means you can pass as much complex, complex expression you wanted to. So I've written 2 3 5 5. So it means it can perform any calculation whether it is related to the multiplication or is it related to the division. So over here I have passed this equation and we are getting the output. So up till now we were just passing some values which we think that, okay, 1 1, I wanted to check the kernel. 1 3, just wanted to check whether it can perform multiplication, can perform division, modulo, or not. So we were passing some random values. Now the next thing in the programming is the variables. Variables are very important because without variable you cannot store anything in the computer's memory. Computer is a big memory, like we have RAM, ROM, we have the memories, right? So when we wanted to store something in the computer's memory, whether it is for the long time, short time, like you have to give it a container. Just like if I wanted to show some water, I have— I need a glass or I need a bottle as well. So it depends which type of a data you are trying to store. You have to store it in some container. When you are storing it in some container, then you can easily access it later on. Because just like in real world, we have the names for different, different containers. Like we have box, we have jar, we have bottle, we have glass, anything it could be. So there are names which we have allotted to each one of the items, each one of the elements that are around us. Same way in programming language, when you wanted to store something, you have to assign a name to that particular thing. So suppose I'm trying to save a number, I'm trying to store a number in the computer's memory. The number is 2, I wanted to store it, so I have to give it a name. So it can be like name_y, like name of the variable. You can name it anything. Suppose this 2 is the meaningful number, maybe it can be someone's age. So you can say that age is equal to 2. So what age is? Age is a variable. We call it a variable, just like we have name in real world, that okay, this is glass, so it means this is the name of that particular item is glass, the name of that particular item is bottle. Same way, when it comes to variable, you have to define a name. It can be any name, you have to make it relatable because whenever you are trying to access that particular item, you have to call with the same name that you have allotted. So over here I have written name_of_variable. Now in the comments I have written cannot start with a number or a special letter. Another thing to note in the programming language is whenever we start writing codes, every time while writing codes we want to store some data which is of our understanding, for our understanding, or just like a notes or keynotes you can say. If you wanted to store something like this, then you have to use the commenting. So different programming languages have different way of commenting something. So just now, like in this, my Python programming language, when you wanted to say, write something like your notes is of one line, it's like a key point or keynote something, then you have to use hashtag in front of that, and that particular sentence will be ignored by the kernel, by the kernel, which will help you execute the code and the notes at the same time. When you wanted to execute both the things, like this is the note and this is the code, and I have written it in the code cell itself, so I can easily execute it, and this particular first statement will be ignored by the kernel, and second statement will be considered as a code. So whenever you add a hashtag in the beginning, it means you are commenting that line. So this line will be commented because I have added a hash. This is for single line. When your note goes to two lines, let's say, and now I'm going to press enter. So it means now, now it's taking two lines. So whenever you would press enter after writing a statement, it will automatically add a hashtag in the front of that line. But if you are initially writing something, let's say I'm writing, these are variables. So it means I have written, these are variables, in 3 different lines. So when you wanted to store something within more than one line, then you have to use this way of commenting, which is using quotations. You have to use 3 quotes in the beginning and 3 quotes in the ending. You can use any quotation, single quote or double quote, any quotation it could be. You, you have to write it 3 in the beginning and 3 at the end. This sentence will also be ignored by the kernel. If you haven't downloaded Python yet on your system, you can watch the video which I have uploaded of setup, a complete setup of Python on your system. You can use that video for downloading and for the complete setup. Now, name of the variable is equal to 2. It means this is a variable and this is the value which we are trying to store, and equal to is the operator which you are using. Equal to is the assignment operator. Then the next variable which I have written is name_2 is equal to Python. Now, earlier we were storing a number, and this time we are trying to store a word. Whenever we say word, text, or any long paragraph or anything similar to this which is related to the characters, then you have to write that within quotation. Either you can use the single quote or double quote, you can, but you have to write it within quotation. If you are not going to write it within quotation, then you won't be able to save it because you will get some errors in this case. So you have to use quotation, double quote or single quote, it depends on you. So you can use it. And I have written name_2 is equal to Python. So this way we can easily store text in the variable and in the computer's memory. I've written x is equal to 2, y is equal to 3. These were just the numbers, so we need not to write it within quotation. When it is number, you ignore quotation. When it is text, paragraph, or something, you add quotation in that. These are the variables. We are using triple quote. Make a note, whenever you are writing something within quotation, this is going to be considered as a string data type. This is called string data type. String means normally text, any character, anything it could be. When we are using three quotation, it means this is multi-line commenting. This is multi-line commenting. And earlier when we were using— when we are using hashtag, it means this is single line commenting. So this is single line commenting when we are using hashtag, and when we are using three quotes, it means we are using multi-line commenting. You can assign the variables like this. You have written, suppose z is equal to x plus y. It means you need not to assign the direct values. You, if you want, you can assign the direct values, but this is not compulsory that every time you have to store the values. You can sometimes store the expressions as well. If you have some expression making some addition, multiplication, division, anything similar to this, you can directly store it in a variable like z is equal to x plus y. So now z is the another variable which contain the addition of both the values which you have stored earlier. Make sure you are writing the variables which you have already created above. If you haven't created these variables, you will get name error. There are multiple types of errors that you will encounter if you are going to start your coding journey. So you don't have to panic when you are getting the errors. You have to simply read the error, which type of error you are getting. Either you can get the syntax error in the beginning, or you can get the name error in the beginning. So these type— these two are the common error that you will encounter when you will start writing your codes. So syntax error means you have written something wrong, you have added some other, you know, maybe comma, colon, or something similar to this you have added, or you are— you have written it in the wrong format. So you have to check the format, you have to, uh, you know, get an overview of what you have written so far and then execute it again. Second is name error. Name error means you haven't defined that particular thing before executing the current code cell. So this is code cell 11, you can see these are the numbers. If you are using Visual Studio Code, then you will get these numbers like this. This shows the execution numbers. This is not the code cell number, this is the execution number in the format you are going to execute it. Suppose after this 11 I have executed it, now I can execute this, then it will show 12 over here. So this shows the execution order, this is not the code cell number, this is execution order. So when I am writing z is equal to x plus y, it means I have already defined x and y before to this column. If you have defined it, that's okay. If you haven't defined it, you will get name error. And then if you are going to print it, you are going to get 5 as a value because x is 2 and y is 3. 2 3 5, which is being stored in the variable z, and you are getting it over here. If you have any questions up till now, just drop it down in the comments. Yeah, anyone, any question? There are two ways of commenting. One is using the hashtag and another one using triple quotes in Python. As I said, different programming language have different way of commenting. So right now we are learning Python. So in Python we have hash and we have triple quotes. Either it can be the single quote or double quote. So you can write it within the single quote as well. This is variable, so I've written variable like this within single quote. Any other question, anyone? So strings can be with reference to execution number 9. Okay, this one you're saying. I have just added it to just differentiate between the code and the text that I have written. You can add a hashtag as well. Generally in SQL and all, like if you are going to learn the databases, then these two minus symbol, like hyphens, will be used to add a commenting. There are only two ways to comment anything in Python, Jadi. First is using hashtag, second is using triple quotes or single quotes. Both are double quotes or single quote, both are same. Now, is this clear to you? Okay, so now next thing is string. String, as I said, that it is the text, single word. It can be, it can be a character, A, B, C, D, to like up till Z, any special character like a dollar symbol, @, the date hash, percentage, anything like this also are considered under the strings. So whenever you are trying to add a character, then also you have to use the single quotes or else double quotes. You can use it single quote or double quote. Now single quote and double quote is enough when you are writing something within single line and you are trying to store it in a variable. Then you can use single quote and double quote. When it comes to more number of lines, then you can use the triple quote and you can save it. Then at that time the commenting will act as a string. So like I have written double quote and you can wrap a lot of other quotes as well within the double quotes itself. Then comes the x is equal to hello. So this is— it means I am trying to save this hello word in the variable x and I am trying to print the x. Now you, when it comes to display something in the output, then you can easily display it directly by writing the variable name, just like I have defined it over here, and I'm trying to write x and I'm getting the output. This works in the Visual Studio Code, but if you are going to use any other environment, any other IDE— IDE stands for Integrated Development Environment— if you are going to use Anaconda, or if you are going to write down the same code in the CMD, it means command prompt, then this won't work. If you are directly writing x, then you won't get any output. If you want to get output, you have to write down print because print is the correct way of displaying anything in Python. So writing print, in the bracket you have to mention the variable that you wanted to print. So like I have written x, I am getting the output. I have written z above, then also I was getting the output over here. But this only works in Visual Studio Code but not in every IDE. For different, different IDE, maybe they have the different ways. Like for Visual Studio Code and Anaconda, it might work, but not in CMD. For CMD, you have to use the method of print. Print is basically a function using which you can display anything. When you are writing print in the bracket, then it goes like you will write print and bracket. This is the correct syntax of writing print. Python is a case-sensitive language. Case-sensitive means when you are writing something in the lowercase, then that has to be written within the lowercase itself. You cannot change it into uppercase. If you are going to change it in the uppercase, it means you are going to encounter name error again. So when you are writing print, it means I have written it in the lowercase, you also have to write it in the lowercase. If you are writing P in caps and other letters in small letters, lowercase, then it will still give you an error because Python is a case-sensitive language. And case-sensitive means whatever you have defined, in whichever way you have defined, you have to use the same way. If you are not going to use the same way you will encounter errors. So when you're writing print bracket, then you can mention whatever you wanted to print. If you wanted to say hello, then you can directly print hello like this. If you don't want to print any text directly, you wanted to print a variable, then you have to write down the name of that variable. Just like in this case, I have x variable, so I can say print x. When you're writing the variable, then you need not to use the quotation because variable is the name. Variable is just a way of storing something in the computer's memory. So you need not to use the quotations to define it. Quotations are required when you are trying to print something directly. So that's how you print anything. Like I have written num is equal to 12, name is equal to Sam. So my number is num and my name is name. Now look at this print statement. Within this print statement, we are writing— we are trying to print multiple stuff. First thing is we are trying to print our message as well. We have stored 2 values because those 2 values were required to be stored in the variable, like num and name. When we are printing it, I wanted to make it more clear to the viewer who is going to view it. So what I have to do is I have to add some instructions also. When it comes to instruction, obviously my instructions are going to be the character, alphabetical character, or it can be the special characters as well. So I have written my number is— my number is just a message, just an instruction, or just a additional info that I am trying to add. So I have to write it within quotation because this is going to act as a normal string. This won't be stored in any variable, this is just a message. So I have— I'm writing print bracket begins within quotation, my number is, then num is the variable which is already defined over here. So I have written num, then again I am writing and my name is, then again which is within the quotation, and then I am writing name value. Now here is one more thing to note, that I am separating each one of this with the comma. Comma act as a separator in the print string. My number is comma name comma and my name is comma name. This is the correct syntax of writing print statement with the additional info and the values, uh, which is being stored in the variable. So this is how the output will be generated for you. Now any question up to this? So sorry. I think so many students are facing the noise issue, so we will connect tomorrow. Until then, you can just practice this, and you can also explore the free, uh, notes that I have added. On top, mate. Till bye-bye.










