1.2 Variables in Python | Python Full course 2024 #learnpythonin2024 #mlwithakansha

Akansha Yadav teaches Python variables as containers for data. Variables can contain letters, digits, and underscores but cannot start with a digit or use special characters like @, #, or %. Use the = operator to assign values, and remember that # starts a comment line.
Chapters
Ladies and gentlemen, in this video we are going to discuss about something called variables. So in the last video we discussed about the writing first code, which was just to say welcome to the Python programming course. So for today's class also, I'm going to create a new file where I'm going to write variable.py. So here we will be writing our code in this file. So let me tell you what variable is. Variable is like a labeled container for your data. Just like in real life we use containers to store some things, same way in computer, in your laptops, you need a container to store your data. It can be any type of a data. Even if you wanted to store your own name, you need a container. So those container— it means those container's label, we call it a variable. So it's very simple. It is a labeled container for data. There are some rules that you need to follow if you wanted to declare any variable. So the first rule says that in variable there can be only letter, underscore. Letters can be like capital letters and small letters, uppercases and lowercases. Both the letters are allowed. Underscore is allowed. It basically, it has to be a combination of a number, letter, and underscore. You cannot use any other special character like @, the date, hashtag, percentage, or asterisk, or brackets, like these things in your variables. To assign any value to the variable, you have to use equal to. So till now, what we have discussed is it can be A to Z, any letter. It can be capital A to Z, any letter. You can use underscore, you can use numbers, it can be a combination of all of these as well. To assign any value, you have to use equal to. So why I have used this Markdown cell? Just to write down a note. So if I will run it, there won't be any, uh, like output will be there, but off to the content only. So let me show you how you have to do it. As I said, there are some conditions. It means you can use only these things. You're not allowed to use @, hashtag, or any of these characters, special characters. So I'm writing name. Name is a combination of all the lowercase letters. So this is a valid variable. You can assign a value using equal to. So name, let's suppose So I'm saying name is equal to Python. So this is going to be a valid thing. I wanted to change it, so I have to right-click and then change cell to code because this is my code. I have to select the kernel Python. So I have written name is equal to Python. If I will run it, there won't be any output, but this is correct, so it is not giving us any error as well. In case I'm going to use any special character, let's suppose I'm trying to add hash and I'm going to run it, it's giving me the output directly, which means it's— is like there is a certain meaning of hash in Python. So basically, if you wanted to write your comments, then you have to use the hash. So I will show you few examples of variables. So name is one of the example which is a valid variable. Another valid variable is _name is equal to programming. This is also correct because underscore is also allowed in this. I wanted to write name_2 is equal to course. Let's see. So all three are the valid one. In this, I'm just using the lowercase letters. Which is correct. And this, I'm using underscore and letters, which is also correct. And this, I'm using all three. I'm using lowercase letters, I'm using underscore, I'm using number as well. I can use capital letter and number. So here, all these 4 variables are valid variables. Let me show you an example of invalid variables. I'm writing 9 name is equal to mine. So in this, it says invalid decimal literal. It means numbers cannot be used in the beginning. You can use it after writing a letter. Suppose I'm writing N9AME, so this is going to be the valid one. But in case you wanted to use it in the beginning, that is going to be the wrong one. If I am writing and, or like dollar symbol, or like name is equal to run, it is also invalid syntax. So in case of if you are going to write numbers in the starting, you will get a syntax error, but specifically which type of syntax error you are getting, it is of invalid decimal literal. In case of this, it is invalid syntax. So these are some of the rules that you need to follow for using the variables. You can assign any type of a value to the variable. Let's suppose I wanted to say age is equal to 50. It's correct because we are assigning a number, which is valid thing in Python.










