Learn Python programming from scratch with this beginnerfriendly course with hands-on projects. This tutorial is perfect for absolute beginners or anyone with zero coding experience. So, time to learn Python programming. Sunonny Damalu created this course. >> Hello everyone and welcome to this complete Python for beginners course. If you have been struggling to learn Python or programming in general, you have landed in exactly the right place. This course is designed specifically for those who want to learn Python but have previously found coding confusing or difficult. Everything will be taught step by step from level zero in a logical and sequential order. This is a project-based course where we will build handson real world projects to truly apply what you have learned. My name is San Malu. I am a cyber security analyst and malware reverse engineer. Welcome to the channel. Now this is a projectbased course. You will be able to apply your learning through hands-on projects because building projects or real world applications is where the true learning happens. In programming, we have to bring different concepts and logic together to build a functional application. That's where you learn the most. After covering the fundamentals, we will build several projects to apply your learning. These hands-on projects include a password generator, MAC address generator, a calculator, port scanner, and password cracker among others many projects. Okay, you can use the timestamps provided to jump to any specific chapter or project. So let's not waste any time before we jump into the code. We will cover a bit of background on the Python language and its uses to set the context for your learning journey. Now if you want to learn Python in a more structured way with additional content and projects, you can check out my course on Udemy. The link is in the description. So what is Python? Python is a highle generalpurpose programming language. Let's start with what a generalpurpose language means. A generalpurpose programming language is not restricted or limited to a single type of task or application. Instead, it can be used to build a wide range of applications for many different fields or domains. For example, you can use Python for web development, automation, data science, machine learning, cyber security, scripting, and much more. Applications for all these domains can be created using the same language called Python. This is exactly why Python is the most popular language learned by almost everyone regardless of their specialization in IT. No matter what field you choose in IT, you will eventually find yourself using Python in some way or other. That's why Python is called a generalpurpose programming language. Now let's talk about what a highle programming language means. Python is a highle language. A highle programming language is designed to be human readable which makes it significantly easier to learn and write. It allows us to use words and structures that closely resemble natural language, especially English. On the other hand, low-level languages like C and assembly require instructions that interact more directly with the computer's hardware. This is what their code looks like. As you can see, these can be quite difficult to master at the beginning. The syntax of these low-level languages is much more complex and require a deeper understanding of how a computer works internally. Now, when we write code in a highle language like Python, it often feels as if we are writing in plain English. This is what a Python program looks like. It is simple to write and easy to understand, right? Highle languages do the heavy lifting for us by automatically handling complex tasks behind the scenes such as memory management, hardware interaction, and low-level system operations. This makes development faster, reduces errors, and allows you to focus on problem solving. So guys, to summarize, Python is everywhere, especially for IT professionals. Learning Python is no longer optional. It has become a mandatory skill regardless of your specialization in IT. Python will play a role in your day-to-day work. Before we can run or execute any Python program, Python must be installed on our computer. By default, a computer doesn't understand Python code. So, the first step is to install something called the Python interpreter. A Python interpreter is a program that reads and executes Python code. When you write Python code, the computer can't understand or execute it directly. Computers do not understand code written in plain English or highle programming languages. Instead, your code must be translated into something called machine level instructions that the computer can understand. This translation is performed by the Python interpreter. The Python interpreter takes your Python instructions or code, converts them into machine level commands, then executes them on the system. So let's install the Python. Open any web browser of your choice. Uh let me open Firefox and type Python. Click on the link python.org. This is the exact link python.org. And once you are here on the homepage, click on the downloads button. Click on it. And this is the downloading page where we can download the Python for different operating systems. We are going to start with the downloading Python for Windows. Here we have two options for downloading Python. Download Python installer manager or you can download the standalone installer. We are going to go with this standalone installer option because it automates your installation. So click on the Python 3.14.3. Click on the link and your downloading will start right away. As you can see my downloading has started. And if you are on Mac OS then click on Mac OS link. Click on it. Scroll down a little. And this is the latest version of Python. So here we have the download link. Click on the Mac OS installer link and your downloading will start right away. It will download the file withpkg or package extension. Now once the downloading is complete now we can proceed with the Python installation. We are going to start by installing Python on Windows. So go to the folder where you have downloaded your Python file. Now double click on the Python file that you just downloaded. Now here it is an extremely important point. We need to check this button add Python.exe to path. Click or check on this button. It will basically make your Python accessible from anywhere in the terminal. So check this button. Add Python.exe ext path. Now double click on the install now option and your download sorry your installation uh process will start right away. All right guys, as you can see setup was success successful. Now click on the close button to close this window. Now let's uh actually verify whether we have installed Python successfully or not. So what you are going to do is open the PowerShell. Press Windows key. Type PowerShell. So click on the PowerShell icon. You will see either PowerShell 7 or PowerShell 5. So click on whatever appears the first. I'm going to click on PowerShell 7. Now type py press enter. As you can see guys, we have successfully installed the Python. So as soon as I pressed enter, now I'm inside the Python's console. Here I can uh write Python code print hello. So we have successfully installed the Python. Now to exit out of the Python's console, press control + D together. Now we are out of the Python's console or you can simply type Python. It will also press enter. It will also take you to the Python's console. Let's check the current version of Python that we have downloaded. So Python version we need to add two hyphens like this. So here we have the current version of Python which is 3.14.3. So guys, we have successfully installed the Python on Windows. In this video, we will install the Z code editor. A code editor is a workplace where you write, modify, and view your programs or code. There are many excellent code editors available, but we are going to use the Zed code editor. Zed is a new next generation modern code editor that is smooth, fast, and extremely lightweight. It doesn't consume excessive system resources such as RAM or CPU like other major code editor VS code. Just like other good code editors, Zed provides helpful features such as syntax highlighting, autocomp completion, formatting tools, etc. which makes the writing code easier, faster, and more efficient. The reason I'm choosing Zed over VS Code is that it is lightweight and uses minimal system resources such as RAM and CPU. This means there won't be slowdowns or lags even on the low-end systems. It is best choice for beginners. Now the popular code editor like VS Code, it is powerful but it is quite heavy and consume a lot of RAM and CPU even for standard tasks. That's why zed is an absolutely outstanding alternative. I have completely switched from VS Code to Zed. It has everything you need in a modern code editor. Plus, it is faster than all other major code editors. Now, let's dive into the practicals. Open any web browser and type uh zed code editor. Click on the link zed.dev. deev. Again, this is the exact link or address z.dev. Once you are here in the homepage, you can click on the download button button that is uh appearing in the in the menu bar here or you can also click on the download button uh here. So, click on the download now. Now, here we can download the Z code editor for different operating systems. Let's download the Z for Windows. Here we have the downloading option for Windows. Click on the download now button. Your downloading will start right away. As you can see, mine has already started. Now, let's download the Z code editor for the Mac OS. So, let me go back to the Mac uh the download page. Now the Z code editor is available for both Intel based Apple computers as well as the the latest Apple computers that use uh Apple silicon chips like M1, M2, M3 etc. Right? So click on this down arrow. If you have Apple computer with Apple silicon chips like M1, M2, then click on this option and click on download. Now your downloading will start right away. If you have an old Apple computer with the Intel chip or Intel processor, then click on Intel chip and click on download. Now your downloading will start right away. As you can see, once the installation is complete, we are good to go. Let's install the Z code editor on Windows first. Now, double click on the Z code editor file that you just downloaded. Double click on it. And here we need to agree term terms of service. Click on I accept the agreements. Click on next. This is the installation path where your Z code editor will be installed. Click on next. And I'm going to check this button create a desk desktop icon so it is easier to access. Now click on uh next. And the download uh sorry the installation has started. It will take probably a minute or two to get the installation done. So wait patiently. As you can see guys, the installation is complete. Now here as you can see we have this button launch zed. It is already being checked. So if I click on finish, it will it will launch or start the the Z code editor. So click on finish. It has started the Z code editor. And for some reasons if your code editor doesn't start then you can open it manually. Press uh Windows key type zed and here you will see this zed code editors icon. Click on it. Then your zed editor should start. This is the welcome window. Now this window only appears when you open the zed code editor for the first time. Here we need to select the theme that you want to use for the the Z code editor. So what I'm going to do is I'm going to go with the dark theme because all the programmers uh prefer or majority of programmers prefer the dark theme. So click on the dark tab as you can see. Now click on the finish setup. So guys we have successfully installed the Z code editor. So I'm going to leave it here. In this video, we are going to configure and optimize the Z code editor. We will make a few changes and set it up correctly so we can start writing our programs efficiently. Let's dive into the practicals. So open your uh Z code editor. Now when you will open the Z code editor, you will see a window similar to this. Just click on new file and uh let me write some dummy code. Print hello there. Now first thing that I'm going to do is uh change the font size. As you can see this font size might not be you know large enough for for the most users or programmers. So let's uh uh increase the font size. uh at the left top click on the click on this menu and uh from here click on open settings. Now here click on the appearance tab and scroll down. As you can see guys here you can customize the font size. Click on the plus button to increase the font size. Okay, I'm going to keep it 18 or 19. As you can see, as you click on the button or increase the font size, the it gets updated inside your code editor. I'm going to keep it 18. It it is good enough for me. So, yeah, that's it for uh this window. Click close this window. Now, next thing that I'm going to do is change its appearance. The Zcode editor has uh as many built-in themes that you can that you can, you know, choose from. Again click on the menu. Click on select theme option and these are the themes that you can choose from. This is the default one dark. You can uh try all these different themes. So let's click on this first theme. Are you dark? Now we have a different appearance. Uh again let's uh open the themes menu. Select themes and uh let's go for iod dark. So guys you you can you can you know experiment around and choose the appropriate theme that suits your style. You can use shortcut for opening themes menu. Press control + K then press control + T. It will it will bring up the themes menu. I'm going to uh select the one dark. Now let's see how we can install extensions. Extensions are basically add-on that expand the editor's functionality similar to plugins in other code editors like VS Code. By default, a text editor comes with core features that are sufficient for basic coding. However, if you need additional support or more features to streamline your workflow, you can install specific extensions to meet those needs. For example, you can in install new themes to change the visual look and feel of your editor. Even though the editor comes with several built-in themes, as we have seen, you can always install additional themes to create a better experience that suits your personal style and workspace. So, what I'm going to do is install an extremely popular theme called called One Dark Pro. So click on the menu and click on down here we have extensions. Click on it. Here you can you know search for the extensions that you want. On the right side if you click on uh installed uh then it will it will display the extensions that you have installed. It already has HTML extension installed which is the default extension which is part of the core uh installation package. Now click on the all and click on the search extension box. Now I'm going to search for one dark pro. As you can see here we have one dark pro and uh it has already been downloaded by almost 200,000 people as you can see. Now click on the install button. It will install the theme in a few in few seconds. As you can see guys, it is already installed. Okay. Click on one dark pro. Now back to the code editor. As you can see guys, now we have a different appearance. Let me open the open the themes menu. Presst controll + k thentroll + t. From here select the one dark pro. Click on it. As you can see now we have a much better appearance. This is the theme that I personally like. I have been using this for like 3 years now. And if you want to uninstall an extension then click on the installed and here you will see the uninstall option uh button. Click on it then it will uninstall the selected extension. So after installing an extension it is always recommended to restart your code editor. So I'm going to close it and let start it again. new file. Similarly, you can install extensions for various purposes such as syntax highlighting. For example, if you want to write code in PowerShell, then you should then you know we can install the extension called PowerShell. This will provide you with essential features like autocomp completion syntax highlighting, error detection, error detection, etc. Right? So here just search for the extension let's say powershell then you know all the matching options will appear here then you can install the appropriate option. So guys this is basically the vast marketplace where you can view browse and install and manage your extensions. Now that we have successfully set up Python and our code editor it's time to write and execute our first Python program. So in this lesson we are going to create our first Python file, run it, check the output and learn about the print function. Now let's dive into the practicals. So open your Z code editor. If you have a different interface than this, do not worry. We are going to start from the scratch. Now on the left top, click on this applications menu. Click on it. Now go to the file. Click on new. We are going to create a new file. So here let me write a simple print statement hello world. Do not worry about this print function that I have just written. It will be explained later in the video in detail. For now write exactly as it is. Print then within the parenthesis and quotes write the hello world exactly as I have written. Now we need to save this file. Press Ctrl + S to save. Now what I'm going to do is create a dedicated folder where I will save all my Python files. So let me save create Python directory. Double click on it. This way it will be easier for me to manage and access all my Python files. Now give a name to your uh Python file. Hello. Py. Now the do.py extension is extremely important. A Python file always ends with py extension. And of course you can give any name to your Python file but the extension must always be pi. Now click on save. Okay. We have successfully created and saved our first Python file. As you can see we have the syntax highlighting as well. So when you save a file, the Z code editor enables the syntax highlighting automatically. Now next step is to run and execute our Python file. To execute uh our Python code, we are going to need to open our terminal. Fortunately, the Z code editor provides the integrated terminal. We don't need to open a dedicated terminal window. On the right bottom we have the terminals uh icon. Click on it. As you can see guys it has opened the PowerShell. By default the Z code editor works with PowerShell. This is the current version of PowerShell. And if you see PowerShell uh version five then then also it doesn't matter. Your code will run regardless. Now I'm going to stack my my PowerShell on my right side. Again go to the terminals icon at the right bottom. Right click on it. Click on dock right. As you can see we have successfully docked or stacked our terminal on the right side. Let me run the clear command. Now to execute a Python file, we need to launch or start the Python's interpreter. So write py as we already know the pi or python command they start the python interpreter. So if I press enter, as you can see, we are inside the python's console. However, we are not going to go inside the python's console. we will instead provide a file name to to the Python's interpreter so it can execute the code inside that file. So press control + D to exit out of the Python's console. Let me clear the terminal. Now write pi. If you are on Mac OS then type Python 3 like this. Okay. If you are on Windows just type pi. Now space. Now we need to tell the Python the exact file name that you want to run or execute. So after space we need to provide either the file name or the full path to the file where your file is saved or stored. My file is stored. Let me go to the directory where I have stored my file. I just want to copy the full path. So inside the python uh directory I have this python file. So uh click on anywhere in your blank space. Now press alt + d. As you can see this is my path. Now we need to copy this path. Press control + c. Now within quotes paste your path. Let me paste it back slash. Now inside my python directory as you can see I have this file called hello.py. So write the exact file name hello.py. I will show you an easier way to copy the path in a minute. For now we are doing it manually. So here I'm telling my Python that uh go to this location d/python. In this directory I have this file called hello.py run and execute this file. So press enter. As you can see we have the hello world being printed. We have successfully executed our hello.py file which is stored or saved at this location. Now the easiest way to to copy a file path is simply right click on your files tab like this. Right click on it. Now copy the path. Let me clear the terminal. Now press up arrow key to bring up the previously executed commands like this. Now within quotes let me paste the path. As you can see we have successfully copied and pasted the file path where it is stored. Press enter. As you can see we have executed our file. Now let me explain this print function what it does. The print function as the name suggests it prints or displays the output in the terminal. When you create real world applications, we always need to print or display information to the user when they run your program. Right? That information can be anything. It can be a simple message like this. Hello world or output or result of a calculation like this as you can see. So if you want to print or display anything uh in the terminal then we use the print function. We just have to tell the print function what you want to print. Here at line number one, I'm telling print function that print this hello world in the terminal. So it printed the hello world. At line number two, uh I'm telling Python to calculate these two numbers then print the result in the terminal. So it exactly did this. So if you want to print anything then write that within the parenthesis of print function like this then it will print or display that in the terminal. So that's how you can create and execute your Python uh Python programs. Now before signing off, there is one one more thing that you need to know about uh executing your Python code. When you provide path to your Python file like this, always surround your path within quotes like this. If you do not provide within quotes, then it can create problems in certain situations. For example, if let's say your folder name is something like this Python code, then uh Python will throw an error. It will treat these two words as separate directories or folders. But when you put it within quotes, then it will treat it as a single folder. So that's why you should always surround your path within the quotes like this. So that's it for this video guys. In this video we will take a deeper look into the print function. We will learn some core uh concepts such as string statements and how to print uh text in multiple lines. Now let's dive into the practicals. Let me write a simple print function. Hello. Hello world. Let's execute the code. Okay, we have successfully printed hello world. So we are going to start with with the string. What a string is a string is nothing but the technical name for text in programming. So this is a string right? Even though you can call it text but in programming we call text string. So this is basically a string. Now one thing that you need to know about uh text or string is that a string is always stored or written within quotes like this. I am learning Python. Okay. Now let's write a mathematical expression. Let's execute the code. we have uh 2 0 which is uh result of 12 + 8. Now Python is treating it as a mathematical expression. However, if I put the same mathematical expression within a quote then it becomes a string. So like I like I was saying if you put anything within single or double quotes in Python that becomes a string. Let's execute the code. This time Python did not calculate these two numbers rather it printed them as they are along with the the plus right because when you put anything within quotes Python treats that as a string. So here Python is assuming that okay since you have written it within quotes it uh it is a string you just want to print these characters. Now if I remove the quotes then yeah Python is going to treat them as numbers or as mathematical expression. So guys that's the most important thing about a string in Python. A string is nothing but the technical name for text and a string is always written within quotes. If you put anything within a code whether uh letters or numbers, Python treats that as as a string. Okay. Now let's move on to the statement. Now a statement in programming is nothing but an instruction that we give to our program. Here I'm giving these three instructions. Right? Here I'm telling Python, okay, print hello world. So it is printing it. Here I'm telling print 12 + 8. I'm basically asking Python to give me out result of 12 + 8. So it is exactly doing this. So statements can be simple lines like this or complex instructions like you know if statement like this. This is also also a statement. Here I'm instructing Python to compare these two numbers. Right? I hope the statements are clear. Now now let's see how we can utilize multi- lines. Okay. Let's say you have a paragraph that spans multiple lines. Hello world. Now here we have a paragraph that is spanning multiple lines. Right? But if I attempt to execute this code, I have an error here. Print syntax unterminated string literal. In Python, you can't break or split a string into multiple lines like this inside the print function. Python expects a string starting with the quote to end in the same line. Okay? When it doesn't see the closing quote before the line ends, it stops or throws an error like this. Now, this can be fixed using three quotes or triple quotes like this. 1 2 3 at the beginning. Now, we need to close these three quotes here. Now, it will fix the error as you can see. So here we are using three opening quotes. So Python is going to check for the three exact closing quotes uh for the termination. Okay. So if you want to write a paragraph that spans multiple lines then always use three opening and closing quotes. Then you know you can write as many lines as as as you like. it doesn't matter. So that's the print function. In this video, we will take a look at escape sequences in Python and how they are used in strings. Uh they are primarily used to format the output of your code such as inserting new lines, creating tab spaces, or displaying characters that usually have reserved meaning. An escape sequence always starts with a backslash and is used to represent characters that are difficult or impossible to type directly in a string. It escapes the normal interpretation of the string to perform a specific function or action. Now let's dive into the practicals. We are going to start by creating a new line. So let's print hello world I am learning Python right let's execute the code and we have the expected result now I want to print this portion of this string in a new line right we have two options uh to achieve this either we can take this portion of the string and put it inside a new print function then it will be printed in a new line. Right? However, this is not efficient. Right? Here we are writing a dedicated print function just to have a new line or print it in the new line. Now there is a better and efficient way to get the same thing done. Let's put it back inside the print function. We can use the escape sequence. An escape sequence is a combination of two or more characters. An escape sequence always starts with backslash followed by a specific character n. Now this combination creates a new line. Let's execute the code. As you can see guys, line after it has been printed in a new line. So anything that you write after this combination back slashn that will be printed or displayed in a new line. An escape sequence always starts with backslash because that's how Python differentiates escape sequences from ordinary text inside a string. So it basically tells computers that do not treat next character or this combination as a regular text or string. Right? Treat it as a special command. So this special command has the meaning that creates a new line. Okay. Another popular escape sequence is t /ash t is for tab. It creates four spaces. Press enter. As you can see / t tab it creates four spaces. So these two are very popular escape sequences that uh that you know we use in most programs specifically this backslash n it creates a new line. Now let's try it uh try back slash i. Now this is not a valid escape sequence or valid combination. Right? There are only certain escape sequences or combinations that have special meaning like backlash n. Not every character that follows a backslash has a special meaning. So when Python encounters backslash n or any valid combination in a string, it interprets that accordingly. So that's it for this video guys. In this quick video, we are going to learn how to create and add comments in Python. Comments in code are notes that we write to explain what the code does. They are used to describe the purpose and logic of the code. Python ignores comments during execution, but they make programs easier to understand, debug, and maintain. Now, let's dive into the practicals. Let me write a simple print function. Hello world. Let's execute it. And we have the expected hello world being printed. Now, let's add a comment. A comment always starts with the hash or pound sign like this. So I'm going to add the commentary the below print function print function prints hello world. Now let's execute the code and we have the same output. If you notice guys, even though we have added this comment, Python did not execute uh this line or line number one because it is a comment. So when a line starts with the pound or hash, Python completely ignores that line. It automatically understands that this is a comment. This is not for me to execute. A comment helps uh people to understand the code or the specific section of the code where you have written the comment. Now see guys, comments are necessary when you are working with a team. When someone else sees your code, without comments, it is very difficult to understand what your code is doing. Now here it is pretty obvious that this print function uh is printing hello world. But when your code has complex logic then comments are necessary. You have to write the comments what that particular section of the code is doing. Even if you revisit your code after let's say a week or 10 days then you are going to need the comments. Otherwise it will take you some time to understand your own code. Now the comments can be added anywhere. You can also write comment like this. It prints hello. It prints hello. Hello world. It doesn't matter where you write the comment as long as it starts with pound. So first character of a comment is always the pound. That's how Python recognizes a comment. Now comments can also be used to disable uh the code or lines of codes like this. Let's see here. I'm printing this and we should have 102 in the output as you can see. Now I want to disable this line temporarily. So what I'm going to do is add pound sign at the beginning. As you can see now the line number four hasn't been executed. Right? We only have hello world. This is because this line starts with pound. So when anything starts with the pound, Python will not execute that particular line. Whether that line is a legitimate Python statement like print or a comment like this, it doesn't matter. Python simply ignores that line. So you can use the uh the bound sign to ignore uh ignore or disable the code lines like this. So that's it for this video guys. Before creating variables practically let me explain what a variable is for absolute beginners. In simple terms a variable is a container that stores data. This data can be anything such as a number text or a file name. Once stored in a variable the data can be accessed, used and reused anywhere in the program. Variables solve two major problems in programming. Data storage and data reusability. Let's start with data storage. Suppose you are creating a banking application. Bank account numbers are often lengthy, right? Usually 10 to 16 digits long, right? Now, if you need to use the same account number multiple times in a program, manually typing or remembering such a long number is difficult. errorprone and impractical. Now to solve this problem, you can store the account number in a variable. Once it is saved, you only need to use the variable's name to access the number. Referring to the variable instead of typing the number manually eliminates mistakes and makes the program much easier to manage. The best part about variables is reusability. Once a variable is created, a variable's value can be accessed as many times as needed simply by using its name. Now let's dive into the practicals. I'm going to create a variable that stores a bank account number. So account number ACC equal to let's assign it a random long value. We have successfully created the variable ACC. This is the variable name. And of course you can give any name to your variable. Then we have this equal to sign. Equal to sign in programming is also known as the assignment operator. The assignment operator assigns data or value to a variable. So here I'm telling Python that take this value or data and assign uh or store it in the ACC variable. As soon as you assign data to a variable, that variable gets created in Python. So this ACC variable is storing or holding this data. And if you want to use this data anywhere in your program, then all you have to do is refer to the ACC variable name. Then you will be able to access this data. Now that we have created a variable, let's see how we can access variables in Python. I'm going to print the value assigned to the ACC variable. So write the exact variable name. The print function is going to display the value stored in the ACC variable. Let me save the code. You will see a difference when I save the code. As you can see, as soon as I saved the code, the Z code editor automatically created or added spaces on both sides of the equal to sign or assignment operator. Well, this is not mandatory. The Z code editor does this for the code formatting. This way, the code looks clean, right? This is also a perfectly valid way to assign value to a variable. Now let's uh execute the script. As you can see, we have successfully accessed the ACC variable or data assigned to the ACC variable. Right? So guys, that's how you can create and access variables in Python. Now one thing that you need to be careful about when accessing variables is never put uh your variable within single or double quotes when accessing them. So if you like this so if you put variable within quotes then Python will not treat them as variables. Let's execute the code. This time the print function has printed ACC as it is. This is because when you put anything uh within quotes in Python, Python treats that as a string. Here the print function is assuming that this ACC is a string that you want to print or display in the terminal. It is not recognizing it as a variable. So to access variables, never put them within quotes. Now it will print the value assigned to the ACC variable as you can see. Now let's uh create a few more variables for a better clarity. ID equal to 1,000 name equal to let's say root. Here we have a very visible difference, right? I have surrounded the text or string value within quotes, not the numbers. Well, you always have to surround the text or string value within quotes in Python. If you don't, then it will throw an error as you can see. So, always surround the string value within within single or double quotes when assigning it to a variable in Python. And never surround your your numbers within quotes because if you surround your numbers within quotes then Python will treat those numbers or values as string. Now let's access these two values as well ACC, ID. Now comma is extremely important when accessing variables inside the print function. we need to separate the variables with commas. Commas basically display the different variables or different pieces of information in a single line of output. So let's access name as well. Let me save the code. As as you can see here also the Z code editor has added spaces. This is also a perfectly valid way to separate variables inside the print function. Let's access uh sorry run the program. As you can see we have successfully accessed values assigned to these three variables. Now let's format this a little account equal to. Now we also need to separate this string from variable using comma like this. ID equal to ID again comma name equal to name variable and we have the expected output. That's how you can create and access variables. Now one thing that I emphasized a lot earlier in the video is uh that variables are reusable. Reusable simply means once you create a variable then you can access that variable as many times as you need in your program. So let's uh access the name variable. As you can see we have successfully accessed the name variable twice. Similarly, you can access the name variable or any other variable as many times as you like. Just write the exact variable name. Like this, we have and now we have accessed the name variable thrice. Now, there are certain rules that you need to obey or follow when creating variables. So what I'm going to do is get rid of uh most of the stuff in my program. The rule number one for creating variables in Python is a variable name can't start with a number. For example, one ACC. This is not a valid variable. As you can see, we have uh an error here because a variable name can never start with a number. Your variable uh names can have numbers uh just not at the beginning. You can include numbers at the end or middle like this. Account number one. This is a valid variable as you can see. Now a variable can only have one special character. That special character is underscore acccc_1. This is a valid variable name in Python as you can see. Now other special characters are not allowed in the variable names like uh at the rate dollar sign. These are not allowed in a variable. The only special character allowed in variables is underscore. Python is a case sensitive language. It means it treats lower case and uppercase characters differently. For example, ACC and ACC in uppercase. Now these two are valid variables and at the same time they are different variables even though we are using the same letters for for the names since the second variable is in uppercase letters Python is going to treat it as a separate or different variable. So let's execute uh sorry let's access the second variable ACC. As you can see we have accessed both the variables. The topic for this video is primary or fundamental data types. In programming a data type is a very important concept. As we have seen variables can store data of different types. Data exists in many forms. For example, 45 is an integer data type. 23.5 is a float or decimal data type. Root is a string data type. These are primary data types. We can create variables to store different types of data. And each variable can hold a different value depending on its type. This allows us to store any kind of data in a a Python variable. Python has many built-in data types available by default. We will cover each of them as we progress through the course because explaining them all in a single video is not practical and helpful at this stage. Some of more advanced secondary data types require understanding of a few basic concepts first. So for now let's focus on the essential primary data types that we we use on a daily basis. Uh I'm going to create uh multiple variables and assign different types of data uh to them. A equal to 78 name equal to root salary equal to a decimal number. Now here we have three different variables right? A name and salary and all these variables are storing different values. A it is storing an integer as you can see name it is storing a string and the salary it is storing a completely different data that is a decimal number. This way guys, you can basically assign any type of data to a variable, right? You don't need to explicitly tell Python the type of data that you are assigning to a variable. Python automatically figures that out in the background and allocates the appropriate memory space for them. So as soon as you assign uh data to a variable in Python, that variable gets created, right? You don't have to worry about the type of data you are assigning to a variable. Now we have a type function in Python that basically tells us the type of data that is being assigned to a variable. So type inside the parenthesis specify the variable name or a value. Let's execute the code. As you can see, it is telling int class int. int means this a variable is storing an integer value. Print type name. Now as you can see string the name variable is storing a string value. Similarly, and the salary variable is storing a load or decimal number. Now, float in Python basically represents a decimal number. Now, these are basically called the primary data types in Python that we use almost in all our programs. And now these are just the very basic data types in Python. Python have has many more data types. Uh we have secondary data types like uh uh like uh list, tuple, sets a and many more. We also have the boolean data types. We will cover all these different data types as we progress uh in the course. Okay, so that's pretty much it for this video. In this video, we will explore string functions in Python, more accurately known as string methods. Python provides a wide range of built-in methods that let us efficiently manipulate and analyze strings. These methods are absolutely essential for text processing and output formatting. For example, using built-in methods, we can find length of a string, convert uh text to uppercase or lowerase, slice, trim or modify strings, and much more. Let's jump into the practicals. Let me create a variable and assign it a string value because we are going to manipulate strings. Uh let's say root admin user. Now first thing that I want to do is check length of this string. Length. Checking length simply means counting how many characters are uh in a string. So print the function for checking length of a string is length len parenthesis. Inside the parenthesis we need to provide either a string or a variable name. I'm going to provide the variable name name. The length function is going to uh is going to count how many characters are stored in the specified variable name. Let's execute the code and we have 15 in the output. So there are total 15 characters in the uh string. Right? The spaces are also counted. Let me add two spaces, one at the end and one at the beginning. and we have length 17. Now here I am providing a variable name. Right? Now we can directly provide a a string value uh to it as well. Let's provide let's say admin. This time the length function is going to check length of this provided string admin which is uh five I guess. As you can see now I want to convert all these lowerase letters into uppercase. Print syntax is simple. First write the string or variable name where you want to perform this conversion uh let's say name. Now the function for converting lowerase letters into upper case is upper sorry upper. Now the way this upper function works, it will take all the lowerase letters stored in the specified variable name then convert them into uppercase. As simple as that. As you can see all the lowerase letters have been converted into the uppercase. Right? Now just like the length function, we can directly provide a string value to the upper function. Let's say root. This time the upper function is going to take this root or lowerase all these lowerase letters and convert them into uppercase as you can see. Now let's convert lower case uh sorry uppercase letters into lower case. Let's add uh uppercase letters in this string. root user name dot function for converting uppercase to lower case is lower parenthesis. And uh this time the lowerase function is going to take all the uppercase letters stored in the name variable then convert them into lowerase letters. As you can see the root user which is in uppercase letters has been converted into lowerase. Just like the length and upper functions we can directly provide a string value uh to it. So let's say root in uppercase. This time the lower function is going to convert these uppercase letters into lower case as you can see here. Now let's capitalize the string. Uh, let me get rid of uh uppercase letters. Print name dot capitalize parenthesis. Now the capitalize method converts the first letter of a string into into uppercase. So here in this string the first letter of this string is R. So capitalize function is going to take this first letter and convert it into uppercase. As you can see R of the root has been converted into the uppercase. Right? So that's the capitalize function. We have a similar function called title. So name dot title. Now the title function capitalizes the first letter of each word in a string. Right? In this name string as you can see we have three words and all are in lower case. Now the title function is going to take the first letter of each word in this string then convert into uppercase as you can see right the next function that we are going to cover is replace. I'm going to replace let's say root with something else. So print name. Now write the replace method. Now you have to tell the replace function two things. One, what you want to replace. I want to replace the word root. So write the root comma. Now specify what you want to replace the root with. I want to replace root with demalu. Let's execute the code. As you can see the demalu has the root has been replaced by the dimallu. So the way replace function works is it searches in the string that you have specified to it. In my case it is name. So it will search for the word root in the value stored in the name variable. It will search for the root. If it finds the root then it replaces it with dalu. So it did find the root and it was replaced by demalu. As you can see now let's print just the name variable. As you can see guys at line number four we printed name. Here we have the original string being printed root admin user. So the replace function doesn't actually modify the actual value or data. So what it does it takes the value that you supply to it makes changes then returns it. It doesn't modify the original string. Now if you want to use the modified string later in the program then what you can do is store that modified uh value in a new variable. Let's say replace replaced value equal to this print replaced. The replace function is going to replace the word root with demalu then return or assign the modified string to the replaced variable. Then down here I am printing the replaced variable which is holding the modified value as you can see. Now, next thing that uh that um I'm going to cover is the string slicing. The string slicing simply means slicing or extracting a specific portion of a string. For example, we have this this string. I don't want to display this portion. I only want to display or print this particular portion. To achieve this, we have to use the string slicing. Uh let's make it uh a bit realistic. So what I'm going to do is uh create a URL variable and assign it a URL. https google.com print URL. As you can see, we have printed this complete URL. Now I don't want to print this portion, right? I only want this google.com. Okay. So, inside the print function, write the exact variable name where you want to perform this slicing. Now, write the square brackets like this. Now, specify a number. I want to skip these letters. So, how many letters are in these? 1 2 3 4 5 6 7 8. So, specify eight then colon. it will basically skip the first eight characters or whatever number you specify here. So it will skip the first eight characters in this string and print the remaining uh characters in this uh specified string which is URL. As you can see we have the expected output. We have successfully sliced or extracted this portion. We skipped this portion right? So whatever number you specify before the column, it will skip those many characters from the left and uh print the remaining characters. As you can see, now we can also extract from right. To extract from right, we need to use minus. So minus 4. So minus4 means it will skip the four characters from the right. So four characters are 1 2 3 4. And as you can see it has skipped these four characters. Now I only want to print this portion Google. I want to slice this string from the middle. Right. Well here we need to use both positive and negative indexing. First I want to skip these many characters from the left. So I think they are total eight. So specify 8 colon and I want to skip 1 2 3 four characters from right. So write uh minus4. Let's execute the code. As you can see we have Google. It skipped eight characters from the left and minus4 it skipped four characters from the right. Now next function that we have is count. Uh let's say root user root admin print. Okay, let's uh rename it to name name dot count root. Now the count function basically counts how many times a substring is appearing inside a string. Now this is a complete string and this root as you can see this is part of this substring. Substring means uh a string that is part of a bigger string. It counts how many times the specified substring is present. So the count function is going to check for this root substring in this name variable. How many times it is appearing. Let's execute. We have two. It means the root is present two times in this string. Right? It indeed is true, right? It is appearing twice. Let's add another root. We should get three. As you can see, root is appearing three times. Now, next method that we have is uh is called strip. The strip method is used to remove spaces from a string. It removes spaces from end and beginning of a string. So let's add one space at the end and one space at the beginning of this string. Print let's check length of this string. length of uh the string before applying strip function is length name and let's execute the script. As you can see length of this string before applying strip is 27. Now let's apply the strip function. Specify the variable name or string where you want to remove spaces. Name dot strip. Now let's print the name variable. Now the way the strip function works is it removes spaces from the beginning and end of a string. So it will remove these two spaces. Let's execute this code. As you can see length before applying strip. Okay. Uh let's uh write uh length after applying strip function. As you can see, we have the same output. Length before applying and length after applying strip 27. Just like the replace function, the way strip function works is it doesn't actually modify the actual value. Okay, it basically takes the value that you supply to it then modifies it and returns the modified value. Here we are not storing the returned value that the strip returns. So name equal to name dot strip. This time we will have a different output. As you can see length before applying strip 27 after applying 25 because it removed two spaces one from the end one from the beginning. So length became 25. Now let let me explain this portion here. uh as I mentioned earlier the strip function doesn't actually modify the the actual value of a string. So what it does is it takes the value that you specify or provide to it makes changes it removes spaces then returns that value. Right now here we are storing the returned value in the name variable. Now the name variable is storing the returned or modified value. So old value gets overwritten by the new modified value. So we get 25. And of course you can assign the modified value in a different variable like this name one. So that's how this strip function works. Now there are two variants of this strip function. R strip and the L strip. So R strip removes space or spaces from the right side of the string. Let's execute. As you can see, we have 26 because our strip only removes spaces from the right side. Since there is one space, so it was removed. So length is 26. We also have the L strip. It removes space or spaces from the left side of a string which is this. It removed one space. So we have 26. Strip removes spaces from both sides and R and L strip remove spaces from right and left sides respectively. In this video we are going to learn about string formatting. It is an important concept for writing clean and efficient code. String formatting in Python allows us to insert variables or values directly into strings. Up until now we have been combining variables and strings using commas. Right now we will learn how to achieve the same thing but in a much more efficient and elegant way. Now let's dive into the practicals. Let me create a few variables. Name equal to root, ID equal to 1,00 and print. I want to insert these two variables directly inside my string. To achieve this, we need to use the fring. F string stands for string formatted. To enable fringing or string formatting, we need to write the f letter immediately after the opening parenthesis like this. Now within quotes, we can insert variables inside the string. My name is within curly brackets write the variable name that you want to access. Let's execute the code. As you can see, my name is root. We have successfully inserted the name variable inside the double quotes or the string. The syntax is simple. First enable the f string by writing f at the beginning. Then uh to insert variables we need to write the exact variable name or variable names within the curly braces like this. Now let's insert the ID variable. ID equal to within quotes ID and we have accessed the both of these variables ID and name. My name is root ID is 1,000. Like I mentioned earlier, we can insert not only variables also mathematical expressions within a string using string formatting. Just write your expression within uh the curly braces like this. Well, let's say 34 into 4. Let's execute the code. And we have the output 136. So, it successfully performed this mathematical calculation. Right? Similarly, you can perform any calculation. Let's say 48 9 divided by 15. Let's see what we get in the output. Okay, I forgot the division operator. So, 49 divided by 15 and we have the expected output. My name is root and this is the result of this division. However, the decimal places are out of control. Right? We have these many decimal places. I only want to display maybe two or three decimal places. To control the decimal places after the second number, write colon dot write to F. Now this time it will only display two decimal places or whatever number you specify after dot as you can see. So that's the beauty of the string formatting. It not only allows us to insert variables or mathematical expressions within a string, it also allows us to control these decimal places. Let's say four. Now it will display four decimal places. As you can see, this way it looks much more cleaner and readable. It is easier to write and read the code this way. Another method for uh formatting string is the method called formatter. So let's remove this print. Then the curly brack bracket after the closing quote write dot then format within format parenthesis write the variable name that you want to insert. Let's execute the code. Okay, we have an error at line number three format name. Okay. Okay, we need to remove string formatting because with format method we can't use the f string. So remove it and the code should work just fine and my name is root. So the way the format method works is first we need to mark the spot or spots where we want to insert the variable. Now the spots are marked by the curly brackets. So the variable will be inserted in this curly brackets spot. Here I have marked this spot and the format method is going to insert the name variable here in this marked spot. Let's say ID is ID. This is the second spot. And now provide the variable name ID. Now format method is going to insert name variable in the first spot. the ID variable in the second spot that has been marked as you can see. Okay, Fring. Okay, we have this F string enabled. I did not enable it. It is the Z code editor that is automatically inserting this F string at the beginning. I don't know why it is doing it, but yeah, that's what it is. Now, let's uh execute the code. As you can see, my name is root, ID is 1,000. So that's how the format method works. First, we need to mark the spots where we want to insert variables using curly braces. Then uh inside the format method, we need to write the variable names that you want to insert. In this section, we will explore operators and mathematical operations in Python. Uh this is a theoretical introduction which is absolutely essential. Each type of operator will be covered practically one by one in the upcoming videos. So what exactly are operators? Operators are symbols used to perform specific mathematical or logical operations on data values or variables. They take one or more values as input and produce a new value as output based on the defined operation. For example, the plus sign is an arithmetic operator that performs addition. It takes two numerical values as input and returns their sum. Similarly, Python provides other arithmetic operators like subtraction, multiplication, division and modulus. These operators are essential for performing various calculations and are the building blocks of mathematical expressions. They are used extensively in programming or specifically the math ccentric applications. Operators in Python can be broadly categorized into four main groups. Arithmetic, relational, logical and equality operators. Arithmetic operators are used to perform basic mathematical calculations. These are the arithmetic operators. Addition, subtraction, multiplication, division and modulus. Then we have relational operators also known as the comparison operators. They compare two values and return a boolean result true or false. Examples include less than, greater than, greater than equal to, less than equal to ATC. They are often used in if statements and loops to control the flow of program. We also have logical operators. They combine multiple conditions and return a boolean result. Examples of logical operators include and, or, and not. They are useful when you check multiple conditions at the same time. We also have some other operators that we will explore as we progress in the course. In the upcoming videos and sections, we will explore each category of operators in detail one by one. In this video, we will perform arithmetic operations. We are going to perform the basic arithmetic operations. Let's start with addition. addition is 45 + 56. The second arithmetic operation operators that we have is uh multiplication. Multiplication is into 56 into 8 67. Then we have subtraction. Subtraction is 34 minus uh 4 print then we have modulus remainder is 45 modulus by 4 and finally we have division. division division is 45 divided by 5. So these are the basic arithmetic operators that we use in all the math ccentric applications. So let's execute the script and see if it is working as it should. Okay, we have the expected result. addition, multiplication, subtraction, remainder, division. So everything is working as it should. Now instead of directly using values, we can store values in variables. Then use the variables. This is the convenient way or the preferred way to perform calculations. First store the values in variables. A equal to 67, B= 6. Let's replace values with a + b a into b a subtract by b a modulus b a divided by b. Let's execute the script. It will produce the same result as you can see. However, here we have in division, as you can see, we have a lot of decimal places. Now, to control decimal places with variables, we need to use the string formatting option, right? So, F enable the string formatting and put sorry, not here. I think division is the last operation. So, enable the string formatting. Now put this expression within the curly brackets like this colon point how many decimal places you want. Let's say 2F. So after the second variable write colon dot 2F. 2F means it will display two decimal places. Uh let's execute the script and we have the perfect output as we wanted. So that's it for this video. In the next video, we are going to create a dynamic calculator. In this video, we are going to talk about the boolean data type and relational operators in Python. These two concepts are deeply interconnected. They work together to help your program make decisions. A boolean value can be only true which is represented or interpreted as one in numerical context or false with uppercase f which is represented as as zero in the numerical context. Boolean operations work by taking one or more inputs and these inputs must be either zero one or true false. The boolean operation then produces an output that is always either true or false. Boolean operations are used with logical operators like and or not. They are widely used in programming to make decisions particularly in conditional statements, comparisons and logical operations that control the flow of program. Let's dive into the practicals. I'm going to demonstrate the the boolean data type with the relational uh operators. The output of a relational operation is always a boolean. It is either true or false depending on the expression being uh being evaluated. So print I'm going to check if 12 is greater than six. Now this is called the relational operator. Greater than relational operator. We will cover the relational operators in detail in the conditional statements section. Okay. So what Python is going to do? It is going to evaluate this expression if 12 is greater than six. Output of a relational operation is always either true or false. Now if condition is true then it returns true. If it is false then it returns false. What do you think the output of this operation is? This is obviously true right? 12 indeed is greater or bigger than six. So let's see what we get in the output. We have the output true, right? Because this expression is being evaluated to true. Now uh let's say 12 greater than 60 63. What about this? This is false, right? 12 is not greater than 63. So it will return the boolean output of false as you can see. So that's the boolean data types for you. Now boolean data types are used for decision making in in if statements, loops and other control structures that we will cover in the upcoming uh upcoming sections. Now we can also store a boolean value to a variable. For example, a equal to true. Remember guys the T of true is always in upper case and f of false is always in upper case as well. Okay like this a now do not surround the boolean values true and false within within quotes. If you do surround within quotes then Python will not treat them as as a boolean value rather it will treat them as a string. For example, let's uh check the type of uh data that the variable a is storing. As you can see class bool it means it is uh the a variable is storing a boolean data type. What if I surround this within ports now we should have string as you can see. So, so whenever you put anything uh between quotes whether single or double quotes, Python treats that as a as a string. In this video, we are going to talk about inputs in Python. How to collect or take inputs from users or keyboard. When you create programs, you will often need to ask users for some kind of input. This input could be anything. a name, a number, or even a choice between different options. Once we collect the input, we can process it and then display a result back to the user based on what they entered. For example, if you are building a calculator, you need to collect numbers from the user so that your program can perform operations like addition, subtraction or multiplication. Understanding how to take user input is one of the most important and fundamental steps in making your program interactive and dynamic. Now let's dive into the practicals. Let me create the variable x. X equal to input. The X variable is going to store the user input. Now the input function in Python is used to collect user inputs. It basically allows us to enter inputs from the keyboard. Now within parenthesis quotes within quotes we need to specify a prompt. Prompt simply means the message that you want to display to users. Here we need to specify what your program expects user to enter. I'm going to request user to enter a number. Right? So enter enter any number and let's print the variable x which is going to store whatever a user enters from the keyboard. You have entered x. Let's run the script. Enter a number. As you can see guys, this is our prompt which is requesting user to enter a number. And then we have this cursor. It is basically waiting for me to enter some input or a data. So let's enter a number. Now press enter. As you can see, you have entered 5 6 5 6. Right? So input function allows us to enter inputs from the keyboard. And whatever input you enter that input gets stored in the variable that you specify here. So x is storing a user input. Then down here I am printing the x. Right? That's why we have the the output you have entered 56 56. This is exactly what I entered. Now here we have a minor problem right? There is no space between the user input and and the prompt which doesn't look uh good. It can easily be fixed. After the prompt create a space like this. Now we have a much better output. You can make it even uh better or fancier. just uh write something like uh greater than sign for a better user experience like this. Now let's create a few more input fields for a better clarity. Now I'm going to request user to enter their name. Name equal to input. Enter your name. Let's print name. Hello name. So enter any number. Let me enter 78. 78. It gets stored in the variable x. Press enter. Now enter your name root. Now the root gets stored in the name variable. Down here I'm printing both of these variables. Right? Press enter. As you can see you have entered 78 hello root. So these are the exact inputs that I entered. Right? This way you can create as many input fields as you like. Now let's move on to the most important part of the input function. Let me get rid of these two lines. By default, the input function treats all inputs as string. So, whatever you enter, the input function is going to treat that as as a string. Let me actually show it uh to you. Here I am going to enter 56. Okay. So, what I'm going to do is check its type. So we have the type function which checks the type of data that a variable is storing. Right? So here type x. I'm going to enter a number 56. Press enter. As you can see guys, x is a string even though it is clearly a number. This is because that's how the input function works. By default, it treats all the user inputs as strings. whether you enter a string or a number, it is going to treat them as a string. Now, this can create problems when performing calculations or mathematical operations because to perform calculations, we need numbers. For example, if you are building a calculator, then you have to ask user to enter numbers. But when you enter numbers, the input function is going to treat that as a string. On strings, you can't perform calculations. To perform calculations, we need numbers like integers, decimal numbers, ATC. Let me try to perform calculations. X + 6. X is storing the user input plus 6. Let me enter a number. As you can see, we have an error here. Can't concatenate strings. We cannot perform addition or any operation with strings. We need the numbers for that. In the next video, we are going to fix this. We are going to continue from where we left off in the previous video and learn about the type casting. Type casting allows us to convert one data type into another. For example, turning a string into an integer, an integer into float or float into an integer. Now, why do we need type casting? Well, this is extremely important in Python because as we saw in the previous video, whenever we take input from a user, input function treats that input as a string by default. The problem is that strings can't be used in mathematical calculations. So even if a user enters a number, Python still sees it as a a string or text. As a result, we will not be able to perform any calculations with it. Therefore, to actually perform calculations or use the value correctly, we need to convert that input from a string into the correct data type such as integer or float. That's exactly what type casting helps us uh do. It converts one data type into another. Now let's dive into the practicals. I'm going to start with a simple uh example. Then later we will convert user inputs into numbers. Okay. So a equal to 45.56. Now this is a decimal number, right? So what I want to do is convert this decimal number into an integer. I want to remove this decimal part. So a equal to int. Now int is a function that converts other data types like float into an integer. Now within parenthesis specify the value or variable that you want to convert into the integer. So what integer function is going to do? It will take the value stored in the variable a and convert it into an integer. It will remove the decimal part from this value. Then store the integer value into the variable a. Let's print a. As you can see guys, 45 the decimal portion has been removed. Let's print it before the conversion or type casting. As you can see guys, here at line number two, I'm printing a before converting it into an integer. So we have 45.56. At line number three, I'm converting this decimal value into an integer. And after converting it into an integer, we have the output 55. Right? Let's actually check the type as well a as you can see type integer and here we have the type float because before converting it into an integer here this is a decimal number. So we have the float which represents decimal numbers and here after converting it into an integer it has been converted into an integer. So we have the data type int. Similarly you can convert other data types uh as well. For example a this is an integer right? Let's convert it into a float. The function for converting an integer into a decimal number is float. So float a. So float is going to take the value stored in a and convert it into a decimal number or float. Let's execute the code. As you can see guys, here it has added the decimal portion 44 45.0. Right? Even though the original value of a doesn't contain any decimal portion. But here the float function converted this integer into float by adding the uh dec decimal places. Now what happens if you put a number within code okay before that type a. Now it is going to show integer. Right now what happens if I put this integer within single or double quotes? As you can see now we have string. So if you put anything within single or double quotes, Python is going to treat that as a string whether it is a number, boolean data type or a string. Similarly guys, we have many other functions for for performing type casting like uh string list tupal ATC. We will cover all these functions as we as we progress in the course. Now let's jump into the input function. How to convert the user inputs into a number like float or integer. A equal to input enter a number. The steps remain the same. So a equal to int. I want to convert user whatever user enters into an integer. So within parenthesis write a. Now what is a? A is storing uh the user input. So whatever user inputs that gets stored in a then we are converting that a into an integer then storing that back in the variable a. Enter a number as you can see. Now let me try to add let's say user input to seven. Let's execute the code. Enter a number. Press enter. This time we have 76. Right? So what happened is that I entered 67. It got stored in the a variable. Then down here I'm converting the variable a into an integer because by default as we already know the input function treats input as string. So I'm converting string into an integer then storing it back in the a. Then here I am uh performing the addition. So whatever user enters I am adding + 7 to it. Okay. Now what happens if I remove this conversion or type casting it will throw an error. As you can see, we have the type error because here I entered a number which is 34. Python is treating it as a string. So here Python is trying to add string to a number which is not a valid expression. But if I convert the user input into integer or float, then yeah, we can perform calculations easily. Now let's uh accept second input b equal to int b. Now I'm going to add a + b. Whatever user enters I'm going to add those two numbers. Enter first number. Enter second number. As you can see we have 61. So here the first number gets stored in the a. second number gets stored in the B. Now I'm converting both of these inputs into integers. Right? So here A equal to int a. So A gets converted into integer. Then it is stored in A. Then B as you can see I'm converting B also into an integer. Storing that converted value in B. Then down here I'm performing the calculations. Now a simpler way to convert user inputs into numbers or other data type is simply specifying uh the int function here like this int open opening parenthesis. Now close the opening parenthesis of int at the end like this int close it here and we will have the same output. As you can see, it is not throwing any errors. So what basically is happening? Python first processes the input function. Once user enters an input, then the int function is going to convert that input into an integer and store the converted value back to the A and same steps are repeated for B. Right? We can also use you know load like this. As you can see now we have uh output with decimal values. Okay, we will cover this more in details in upcoming videos. In this quick video we will take a look at the plus operator in Python. Yes, it is an arithmetic operator that performs addition, right? But in Python, it does more than just math. The plus operator can also concatenate or combine strings together. Its output depends on how and where you use it. With numbers, it performs addition. With strings, it joins or concatenates the strings. With lists or tupils, it combines them. Python is smart enough to change the behavior of plus based on the data type you are working with. Now, let's dive into the practicals. So I'm going to start with a simple example. So print. Now this simple print statement is going to add two numbers. As you can see it is working or behaving expectedly as it should. Now what happens if I try to add two strings root plus uh let's say demalu now this time as you can see guys it has concatenated these two strings right so that's how the plus operator works when you provide it two numbers then it adds them and when you provide create two string values then it concatenates them or it merges them. You can concatenate as many strings as you like like this plus space. So this time I'm concatenating root plus here uh this is a white space. So it will add space between these two words. Let's uh execute. As you can see, it also works with variables. So, what I'm going to do is create two variables. Let's say fame equal to root lame equal to admin. Print. Now I want to display root and admin as a full name which is simple. Print the full name is fame plus all I need to do is concatenate these two variables like this. So since these two variables as you can see they store string values. The plus operator is going to take these two variables then concatenate them into a single string. As you can see full name is root admin. And if you want to add space a space between these two words then we can concatenate a white space like this. Make sure that you know you add plus signs appropriately like this. after fn name then plus wide space plus as well. Now this time we have a much better or formatted output. So guys like I mentioned uh earlier in the video the behavior of the plus operator depends on the type of data you feed it. If you feed it two numbers then it adds them or calculates them. If you feed it two string values, then it concatenates or combines them. Now what happens? What happens if you attempt to do something like this? Uh here I'm providing it two different data types 12 + root. 12 is an integer of course root is a string. Let's see. And we have an error. unsupported upper hand plus int and string right so here we have an obvious error because Python is confused here what I'm trying to do right here I'm trying to add a number with string that's why we have an type error so it it only works if you provide it the same data type so if you provide two strings it concatenates them if you provide two numbers it adds them so plus also works Same with other data types like tupils and lists as well that we will cover later in the course. We are going to continue from where we left off in the previous video. In this video, we will perform arithmetic operations based on user inputs. We will ask the user to enter numbers and then perform calculations on them. This is where we will bring together everything that we have learned so far. Arithmetic operations, type casting and combining them with user inputs to create a complete interactive or dynamic program. Now let's dive into the practicals. First we are going to collect or gather the inputs from user. Then we will perform arithmetic operations on those inputs. So a equal to input. Now we need to to convert the user inputs into integers because as we already know by default the input function treats all inputs as string. So we can't therefore we can't perform calculations on strings. Right? So first we need to convert the input into integer. So int opening parenthesis close the integers parenthesis same uh thing repeat the same thing for uh the second input integer and close the integer function. So whatever input a user enters that input will be converted into integers once it is converted now we can uh we can basically perform mathematical operations with the user inputs. So let's uh perform arithmetic operations. Addition is a + b. Print multiplication is a into b. Print remainder is a modulus b and the division a division is a divided by b. We also have the subtraction of course. Print subtraction is a minus b. Let's execute the script. Enter first number 23 5. As you can see guys, we have the the expected output or well formatted output. We are asking user to enter first number, second number. Then we have converted the user inputs into integers as you can see. Then down here we are performing the arithmetic operations on the user inputs. So this is as easy as that. Now what I'm going to do is instead of directly performing arithmetic operations in the print function, I'm going to store the results in variables. For example, sum equal to a + b. So what basically is happening here? We are calculating a + b then assigning that output to the sum variable. Now instead of writing a plus b, we can simply use the sum variable because the sum variable is holding the output of a + b. Now benefit of storing result of a calculation in a variable is that we can reuse that result later in the program wherever it is needed. For example, if I want to use the sum of a + b somewhere down here in the in the program, then I can simply use the sum variable instead of uh you know writing the expression a + b. So it is very convenient and uh the standard way to write the mathematical expressions in programming. Now same thing we can repeat for other operations. Multiplication equal to a into b. So here let's write uh multi. The multi variable is storing the result of a into b. Let's execute the script. As you can see, we have the expected output, right? Let's uh go for uh modulus as well. Modulus equal to a a modulus b. We can give it uh an appropriate variable name remainder. Remainder. Let's replace a modulus b with the remainder. Remainder variable. The remainder variable is of course storing the result of a modulus b. Let's uh run the script again. As you can see guys, we have the expected output. Similarly, you can create variables for rest of the arithmetic operations that we have performed and store the result or output in those variables. then use the variables here instead of writing the expressions directly in the print function. So that's it for this video guys. Thank you very much for watching. In this section we will explore if statements or conditions and how to use them. If statements are also known as conditional statements or decision making statements. They are extremely important in all programming languages. So far we have been writing simple scripts line by line. Now to make our programs a bit smarter, we will use if statements to add conditional logic and make our code more intelligent and powerful. Conditional statements allow programs to make decisions based on the conditions you define. Suppose you want your program to compare two numbers and determine which is bigger. For us, this is effortless. We can look at the numbers and instantly know which is bigger, right? However, computers do not understand anything automatically. You must explicitly program every single decision. No matter how small even something like as basic as comparing two numbers whether it is a simple task like this or a complex operation you need to define all possible scenarios in code. This is what if statements solve. They enable programs to compare values whether numbers, strings or other data types and make decisions based on defined conditions. Now let's dive into the practicals. Write if the if keyword is used to create if conditions or the if statements after if space is very important. Now write the condition that you want to test. Let's say 45 greater than six. The greater than sign is called the relational operator. It checks if the value on the left side is greater than from the value on the right side. Now the way the if statements work is Python checks if the specified condition is true or false. If the condition is true, then Python is going to execute the code that belongs to this if statement. Now every if condition has its own block. In that block we define or write the code that will be executed if the condition is evaluated to. Next step is to write the code that will be executed when this condition is true. So write colon. Colon is important. It basically tells Python that this expression ends here. After this the block or body of uh this if statement starts. Now how does Python uh recognize or identify body of of a control structure like uh this if statement? Well, it uses something called the indentation. Indentation is nothing but the spaces that you add at the beginning of a line. Let me show it to you. Press enter. As you can see here, Python has automatically inserted four spaces, right? Let me go back to the if condition. Press enter. As you can see, it automatically inserted four spaces. This is the indentation. And for some reasons, if your code editor is not inserting spaces automatically, then you need to add them manually. So add four spaces manually like this. 1 2 3 four. Most of the code editors will automatically insert four spaces. Now these spaces are called the indentation. The code that you write with the same level of indentation, that code will exclusively belong to this if statement. I will break down this in a minute. For now let me write condition true 45 is so the way if statements work is Python first evaluates or checks this condition. If this condition is true or false. If the condition is true then it will execute the body or block of this statement which is defined using the indentation. Now since this condition is true, Python will execute this print statement. Obviously this condition is true, right? 45 is greater than six. So it will execute the this line which is written inside the block of this if statement. Let's uh execute the code. And we have the expected output. It has printed this line. Now let me write another print statement to uh demonstrate the indentation. The concept of indentation inside the statement. Now the code that you write with the same level of indentation that code exclusively belongs to the if statement or this if statement. Now as you can see here both of these lines are using the same level of indentation. The indentation is determined by the first line that you write immediately after the if statement. Now first line is using four spaces as indentation. Right? Now all the subsequent or lines after the first line must also use the same level of indentation. Then those lines will belong to the if statement. This time since these two lines are using the same level of indentation, these two lines exclusively belong to this if statement. So if this condition is evaluated to true, these two lines will be executed. As you can see this time we have this output. This condition was evaluated to true. And since these two lines belong to this if statement they were executed. Let me write another line print true. Now we have these three lines that are using the same level of indentation and they belong to this if statement. So if this condition is evaluated to true, these three lines will be executed. As you can see now indentation doesn't always uh has to be four spaces. You can customize it to your liking. The four spaces is basically the standard and default indentation. You can use one, two or eight spaces, however many you like. Now like I like I said earlier the indentation is determined by the first line that you write immediately after the if condition. If first line uses one space as as an indentation then rest of the lines must follow the same level of indentation. This time the first line is using one space as as an indentation but uh remaining two lines are not. So let's see what output we get. We have the error. Now check out the error. Indentation error means we don't have a consistent indentation. But if I use the same level of indentation, now it will fix the error. As you can see, now we have the expected output. These three lines belong to this if statement, right? they were executed when Python evaluated this condition to true. Four spaces is the default indentation. So indentation is important. It will be used a lot as we progress in this course. Indentation will be used with functions, loops and many more control structures. I hope that indentation is clear. Now let's move on to the else statement. The if statement offers two possibilities or two possible outcomes. We can have uh one outcome for true and other outcome for false. Right? Now here Python is going to execute the block of if this condition is evaluated to true. Right? But what happens if the condition is false? Let's say 45 greater than 69. Here condition is false. Right? 45 is not greater than 69. Since this condition is false, the body of if will not be executed. The body of an if statement is only executed when condition is true. As you can see this time we have no output because the body of if is only executed when condition is true. Now what we are going to do is write the code for the false condition. So else write else colon just like the if statement else also has its own block or body that body gets executed when condition is false. Now this time we have false as as an output because the else only gets executed when the condition is false. Okay. So here if condition is true block of if gets executed and if the condition is false the block of else gets executed. Make sure to write the else outside of the block of if that is important. Okay so else is basically kind of a backup right? If the condition is true then block of if gets executed but if the condition is false then block of else gets executed. Just like the if statement else also has its own block which is defined by the indentation. Print inside else block. This time we have these two lines of output because the block of else was executed. So these two lines were executed. Both of these lines use the same level of indentation. Right? Now let's dig a bit deeper into into the if statement. How actually things work in the background. So what I'm going to do is uh take this exact expression and put it in the print statement. Uh let's execute the code. As you can see we have false. This is output of this print statement is false. Now we are using the same expression in the if statement. So the way Python works is first it evaluates this expression then based on the output of this evaluation then it makes a decision. Now here output of this expression is false. So if it is false then the block of else gets executed but if it is true then block of if gets executed. As you can see this time true output of this expression was true right so when an expression is evaluated to true the block of if gets executed that's how it works I hope it is clear and before signing of instead of using uh values we can also use variables like this a equal to this bal now replace values with variable ables. Now here everything remains same except for the variables right here I'm providing the if statement variables a greater than b variable a is storing 67 b is storing five so it checks if value assigned to a which is 67 is greater than five so based on the values it makes a decision now we also have other relational operators like less than Right? So less than operator checks if the value on the left side is lesser than value on the right side. As you can see false because 67 is not less than five. We also have less than greater than equal to. Now greater than equal to is basically combination of two things greater than and equal to. Let's uh make both values same. 67 and let's execute this code. We have false. So here I'm checking if A is bigger than B. Now value of A is 67 and value of B is 67 as well. So obviously it is checking if 67 is greater than 67. Condition is false. 67 is not greater than 67. It is equal to 67. So condition was evaluated to false. The block of else was executed where we printed false. Now what happens if you use greater than and equal to relational operator. It is combination of two things greater than and equal to. So this time first let's execute the code. We have the output. Let me reexecute it. We have the output true. Now here Python checks for two things. First it checks if a is greater than b. Then it checks if a is equal to b. So in first case when it checks if a is greater than b condition is false. 67 is not greater than 67 then we are also using greater than equal to. Then it checks if a is equal to b condition is true. A indeed is equal to b. So this expression is evaluated as true. So we are printing true as you can see. So greater than equal to basically checks if the value is either greater than or equal to. We also have less than equal to. It also works the same as greater than equal to. So that's it for this video. In this video, we will take a look at the else if statement which is written as l if in Python. It's used when you want to check multiple conditions sequentially, not just a single one. In our previous video, we covered the basic if else statement. With if else, you only have two possible outcomes. If the condition is true, the if block gets executed. If it is false, the else block gets executed, right? It gives us only two possibilities. However, in most real world applications, you need to check for more than just two possibilities. In such cases, Python provides the else if statement, which allows us to check multiple conditions and handle different scenarios one after another. Now, let's dive into the practicals. We are going to write a program to determine grade of a student based on their score. Let's say we have four possible grades A B C D and if a student scores let's say 90 and above they get grade A. If they score 80 or above they get B and so on. Now the simple if statement is not enough for writing such programs because it only gives us two possibilities. We need something more complex that that can check for all the four possibilities. That's where we use the else if statements. So let's create a variable score equal to uh 74. Now write if score is greater than 90 then print. Make sure that there is uh the indentation as we discussed in the previous video. Now write else if. Else if is written as l if in Python. L if basically means else if. That's the keyword to write the else if statements. Else if core greater than 70 print grade else if score greater than uh 6 and sometimes uh my code editor doesn't add the indentation. So make sure to add indentation manually. print C-grade. Now at the end we must write the else statement. Else is always defined at the end. Print Dgrade. Now let me execute the code then I'll break down everything. And we have the output C grade. So here I have created the variable score and assigned it the value 74. Now the way the else if statements work is the conditions are checked sequentially from top to bottom. So first uh Python is going to check if score which is 70 is greater than 90 condition is false. 74 is not greater than 90. So it will not execute the block of this if statement. Now Python automatically moves to the next statement which is this else if statement. Here we are checking if score is greater than 80. This time also condition is false. 74 is not greater than 80. Just like the if statements, all else if statements have their own blocks and blocks are defined using the indentation. Just like the if statement. Now since this condition is false, Python moves to the next else if statement which is this. Here we are checking if 74 is greater than 70. This time condition is true, right? 74 is greater than 70. Now if an if condition or an else- if condition is evaluated to true block of that condition gets executed since this condition is evaluated to true block of this gets executed where we are printing this line C grade that's why we have the output C grade now when a condition is evaluated to true Python does not check rest of the else if statements so as soon as this condition is evaluated ated to true. It will not check rest of the else if statements. The code will exit out of this structure and continue executing code that is written after this structure. In the multiple else if statements, the code is checked sequentially from top. Okay. Now let's modify this score. Let's say 93. Congrats, you have earned a grade because here Python checks if score which is 60 93 is greater than 90 condition is true. So block of if was executed uh let's say 67 we should have C grade as you can see. Now what is role of this else statement here? Well, in else if statements, the else block is executed only when none of the conditions are true. So here, let's make uh this all the conditions false. So let's say score is 44. Now we have degrade which is part of the else block. Why? Because none of the conditions were true. So here Python checks if 44 is greater than 9 0 condition is false. Here it checks if 44 is greater than 80 condition is false. Here also condition is false. Condition is false because 44 is not greater greater than 60 since none of the conditions matched the block of else was executed. Right? Degrade. So else is only executed when none of the conditions match or when none of the conditions are true. That's how else if statements work. I hope guys this is clear. Now in this quick video we will learn about the equality operators in Python. Equality operators are used to compare values or data to check whether they are equal or not. There are two primary equality operators in Python. Equal to and not equal to. These operators return a boolean value. They return true if the condition is satisfied or met and false if it is not. Now let's dive into the practicals. So write if 34 equal to. Now here this is a simple if statement, right? where I'm checking if 34 is equal to 34. Let me finish the code then I will break down this code. Yes, both are equal. Equal and we have the expected output both are equal. Now as you can notice here to compare values I have used two equal to signs. So to compare two values we need to use two equal to signs. This is called the equality operator because one equal to sign as you can see here it is used to assign data to a variable. Right? So to compare two values we need to use two equal to signs which is called the equality operator. It checks if two provided values are equal or not. Uh let's write else as well. R not equal. So here Python checks if 34 is equal to 34. Condition is true, right? 34 is indeed equal to 34. So block of if gets executed, right? Yes, both are equal. Now let's make it uh 314. This time we have the output not equal. So here these two values are not equal. The equality operator only returns true if both the values are equal. This time 34 is not equal to 314. Right? So the condition was evaluated to false. That's why the block of else was executed where we are printing this statement. Not. Now we can also use uh sorry compare strings. Now let me get rid of this root. When you want to compare strings, strings must always be surrounded within quotes. So like this root now here I'm checking if root is equal to root condition is true because they are equal values. What happens if I add space not equal? So spaces also get counted. Now here Python is checking if root is equal to root plus space. So these values are not equal. So remove the space and now these values are equal. Let's compare if root is equal to root one. Okay, not equal. Obviously root is not equal to root one. So that's how the equality operator works which is represented by two equal to signs. Now another equality operator that we have is called the not equal to operator. The not equal to operator checks if the provided values are not equal. So if 12 is not equal to 8, print not equal else. The way it works is if the values provided here are not equal. If they are not equal, the condition is evaluated to true. Now here I'm basically checking if 12 is not equal to 8. condition is obviously true. It is not equal to 8. So block of if will be executed. As you can see not equal. Now what if I check if 12 is not equal to 12 and we have equal because these two values are equal. So when the values are equal the block of else gets executed because when values are equal the condition is evaluated to false. That's why we have the else block being executed. But when the values are not equal then the condition is evaluated to true and block of if gets executed. So that's the syntax to write the not equal to operator. We have to write the exclamation mark then equal to sign. You can also add spaces like this. It is also fine as you can see not equal. In this video we are going to cover the different types of logical operators in Python. There are three main types of logical operators and or and not. These are most commonly used with if conditions or statements. Logical operators allow us to combine two or more conditions into a single expression which enables us to perform operations based on multiple conditions. In simpler terms, they let you check multiple conditions within a single if statement. The result of a logical expression is always either true or false. There are three main types of logical operators in Python. And, or, and not. Let's start with the and operator. The and operator checks two or more expressions or conditions. You must provide it at least two conditions for it to work. Let's uh jump into the practicals. We are going to start with the and operator. We are going to start with a simple example. So write if uh let's say 44 equal to 44 space. Now write and the and operator is represented by the and keyword in Python space. Now specify the second condition 55 is equal to 55 colon in the block of if statement we are going to print true all values are uh same or equal. Now let's break uh this down. The way the and operator works is it needs minimum two conditions or expressions to work. Right? So here we have correctly provided two conditions and second the most importantly and operator returns true if all the specified conditions are true. If all the conditions are true then that if statement is evaluated as true. Right here we have two conditions. The first condition says if 44 is equal to 44 condition is obviously true and the second condition says if 55 is equal to 55. Now both of these conditions are true. So when all the conditions are true that if statement is evaluated as true and the block of if gets executed. Let's execute the code and the block of if has been executed. Right? So that's how the and uh operator works. It allows us to combine multiple conditions into one single expression. Now let's combine one more condition and 66 equal to 66. This time we have provided three conditions and all the three conditions are true. Right? Since all the conditions are true, this if statement will be evaluated as true. Now what happens if a condition is false? Let's say 66 is equal to 61. Let's execute the code. And this time we have no output because the way and operator works is it returns true only if all the conditions are true. But here uh one condition is false. So when even one condition among all the provided conditions is false then the and operator returns false and that if statement is then evaluated as false. Therefore the block of if will not be executed. Let's specify the else block. Print false. Now this time we have the false in the output because we have one condition which is false. So this expression was evaluated as false. Like I was saying, you can combine as many conditions as you like using the and logical operator. It allows us to combine multiple conditions into a single expression. Here we have four conditions and since all the four conditions are true, the block of if has been executed. To summarize the logical and operator, it needs minimum two or more expressions or conditions to function and it returns true only if all the provided conditions are true. Now let's move on to the or operator. The logical or operator is similar uh to the end operator but at fundamental level it works slightly differently. So uh let's say if 22 equal to 22 the or operator is represented by the or keyword space 1 = 1 print true else print false. Now the way or operator works is just like the and operator. It needs minimum two conditions to work. We have provided two conditions and it returns true even if one condition is true. Here we have provided two conditions. Both the conditions are true. So it will return true as you can see. Now let me specify a false condition. As you can see, first two conditions are true, but the third condition is false. It will still return true because it only needs one condition to be true. Then it returns true. Now it returns false only if all the conditions are false. This time I have provided three conditions, right? And all of these are false. So when all the conditions are false then it returns false. Therefore the if statement will be evaluated as false as you can see. Okay. Now let's make one condition true. Now here since at least one condition is true it will return true. Okay. So to summarize the logical or operator needs only one condition true then it returns true. It returns false only if all the provided conditions are false. Just like the and operator, it needs minimum two or more conditions. Okay, this way you can combine as many conditions as you like with the logical or operator. Now the third logical operator that we have is not operator. Now the way not operator works is it basically flips or changes a condition. If a condition is true, it makes it false. If a condition is false, then it makes that condition true. Let me show you. If 34 is equal to 34, sorry, uh 34, print true. else we are going to write false. As you can see we have true in the output. Here I'm checking a simple condition if 34 is equal to 34. Obviously condition is true. 34 is equal to 34. So block of if gets executed. Now the not operator is represented by the not keyword. So write not space. Now we have false in the output. Right? This is because the way it works is first Python evaluates this expression 34 is equal to 34. Condition is true. So it returns true. Since we are using the not operator. Not operator takes the result of this expression then changes it to false. not operator makes it false. Now once it is evaluated as false, it will not execute the block of if it will execute the block of else. That's why we have false in the output. That's how the not operator works. It changes true to false and false to true. Now let's make it false. As you can see we have this time true. So here first Python evaluates this condition 34= to 341. condition is obviously false. Now the not operator takes the result makes the false into true or changes the false into true. Once it is evaluated as true the block of if gets executed where we have printed this true right so that's how guys the not operator works. uh we will continue from where we left off in the previous video where we learned the fundamentals and basic working of logical operators. Now we will move on to something more complex to understand them more deeply. We will dive deeper into logical operators specifically the and and or operators. Both of these operators have many practical uses. For example, it is useful when multiple conditions must be true simultaneously, such as validating whether both a username and password are correct. We will create a simple dummy program to check whether the username and password entered by the user are correct or not. Now let's dive into the practicals. I'm going to create a basic authentication script that will check if the username and password that the user enters are correct or not. So uh let me create variable username. The correct username is going to be root and the correct password is going to be admin. So if user enters username root and password admin then uh it will be authenticated and if user enters anything apart from these two then the script or authentication will fail. So first thing that uh we need to do is obviously ask the user for inputs. So name equal to input enter the username and add space after the greater than sign password equal to make sure that you have a different variable name for this password. Okay. If you uh give the same variable names for both of these uh variables then uh this variable is going to override the the value of this variable where we have stored the actual password. Password equal to input enter the password. So let's compare. So, so the logic is going to be we are going to compare the username and password that user enters with the username and passwords that we have stored in these variables. So name the name this name variable as you can see it stores whatever user enters as username if uh it is equal to username that we have stored in this username variable username. Now, and the and operator as we saw in the previous video, it allows us to combine multiple conditions. And we are going to check password as well. If the password, let me copy the exact variable. If the password that user enters is equal to the password that we have stored in the variable here, print authentication. Authentication successful else sorry else print wrong username or password password so let's execute the script then I will break down everything enter username first we are going to start uh by uh by entering the incorrect username and password. Password as you can see wrong username and password. Now let's enter the correct username which is root. Password is admin. The correct password is admin. Press enter. As you can see authentication successful. Here I am asking user to enter a username and password. Username gets stored in the name variable. password gets stored in the password variable. Here I'm checking if the username that user enters is equal to the variable username which is storing the correct username root. Then we are using the end operator. Here we are checking if password is equal to password that user enters. Right? This variable is storing whatever password user enters against the password that we have stored in this variable. Now the way the on and operator works is both of the conditions must be true. So user must enter the correct username and password then both of these conditions will match or will be evaluated to true. Therefore this if statement will be evaluated as true and the block of if will be executed. If the user enters either a username or password wrong, then this condition will be evaluated as false and the block of else will be executed. Right? So this is a very simple yet very useful when it comes to understanding the working of the end operator in real world. So that's the that's how the end operator works. So let me know if you have any questions regarding this. I'll happily answer everything. Now let's uh uh do one example for the or operator as well. So what I'm going to do is I will check if a character is consonant or vowel vowel right vowel characters are these right a i e o and u I'm going to ask user to enter a character then based on the entered character we will tell whether it is um a vowel or consonant okay these are vowel and rest of the characters are consonant So first let's enter a character input. Enter a character. Now I'm going to check if the character is wow or not using the or operator. So if the care the care variable is storing whatever character user inputs. If care equal to I or if care equal to E or care equal to O or if care uh equal to U or if care equal to A, it is a vowel. else print it is a consonant it is a consonant. Now if you remember the way the or operator works is it only needs one condition to be true. Then that if statement is evaluated as true right? So here I'm asking user to enter a character. So whatever character user enters that gets stored in the care variable. So if user enters uh let's uh execute code I it is a vowel right a it is a vowel now let's enter a consonant it is a consonant here in the if condition I'm checking for all the five possible vowels right so if user enters any of the five wow then this if condition will be evaluated as true because we are using or. So the or operator needs only one condition to be true. Then uh that if statement is evaluated as true. For example, let's enter E. It is a vowel. So E that I entered got stored in the care. So I am checking if care whose current value is E is equal to I. Condition is false. Now here care which is E is equal to E. So since the values ma matched the if statement was uh evaluated as true and block of this if statement was executed. So yeah that that's how you can use the or operator. Okay let me demonstrate the consonant uh as well K as you can see it is a consonant. So the value of care is K. So here it is checking if the K is equal to I condition is false. If k is equal to a condition is false. If care or k is equal to o condition is false. If care is equal to u condition is false. If the care which is k is equal to a condition is false as well. So here none of the conditions matched. Since none of the conditions matched the or operator returned false therefore this condition was evaluated as false and the block of else was executed. So that's it for this video guys. In this section we will be learning about loops in Python. Loops are one of the core components in any programming language. A loop allows us to automate repetitive tasks and help us avoid writing the same code over and over again. For example, if you want to print hello world 10 times or display numbers from 1 to 100 without a loop, you would have to write 10 separate lines of code just to print hello world 10 times. Now imagine having to print it 100 times. That would be a big problem, right? It is not only time consuming but also inefficient and completely impractical in real world. That's where loop comes in. With a loop, we can automate such repetitive tasks and get the same result with just a few lines of code. That's the power of loops. Loops automate repetitive tasks by executing a block of code multiple times or as long as the condition remains true. A loop has a block of code similar to if statement. block of loop is executed repeatedly as long as a specified condition remains true. Now let's dive into the practicals. So write for the for keyword is used to create a for loop in Python space. Now write I. Now this I is a variable. This is this for loops variable space. Write in range. I will write the complete code then break down everything. Now parenthesis. Now inside the parenthesis of the range function we need to specify three values. The first value is going to be start value where the loop or sequence starts. So this loop is going to start from 1, the second value is going to be the ending value. How long this loop will run 12. So this loop or sequence starts from 1 and ends at 12, the third value is going to be the increment. After each iteration, this loop will be incremented by one. I know for now it is a bit confusing but it will get crystal clear in next few minutes. Now colon after the colon the block of for loop starts just like an if statement has its own block or body. Uh similarly a for loop also has its own body. Python keeps executing the code that you write inside the body of for loop as long as uh the condition remains true. Press enter. As you can see, it has automatically inserted four spaces. The block of a for loop is defined by the indentation. This is the indentation, right? Just like the if statement. And for some reasons if your code editor doesn't add indentation automatically then you can insert four spaces manually like this 1 2 3 4. Four spaces are the default indentation to define the for loops block or block of any control structure in Python. Now in the block of for loop I'm going to print the value of I. What is I? I is this for loops variable. So write that here. Let's execute the code. We have the output. We have numbers being printed from 1 to 11. So let's break down this output. So this loop starts from 1. This is the starting value. So when this loop runs for the first time, the value of i is initialized to one. the value of i becomes one because here I have explicitly told the range function that this loop starts from one. Now after giving the i variable uh its initial value now python checks if the current value of i is less than the second value that you provide here which is 12. So in the background, Python basically checks if the current value of I which is 1 is less than the value that you specify here which is 12. Condition is true. Right? Current value of I is uh 1. I is less than 12. Now as soon as the condition is evaluated to true, the Python executes the code that you have written inside the block of for loop. So inside the block of for loop I am printing I. So Python prints I. The current value of I is one. So Python prints one. Right? Now since we don't have any lines of codes inside the block of this for loop, control moves back to the for loops structure. Now Python executes this third part of this for loop which is one. This is called the increment value. Now, Python will increment the value of I by 1 or whatever value you put in here. So, current value of I is 1, right? So, in the background, it simply does this. The current value of I is 1. So, 1 + 1 becomes 2. Now, Python updates the value of I with two. Now, the value of I becomes two. The old value which was 1 is replaced by the new updated value which is two. Now Python compares if two is less than the value specified here 12 condition is true. Now Python executes its block in the block it prints value of i which is two. So it prints two. Now control goes back to the for loop again. It increments the value of i by one. The current value of I is 2. So 2 + 1 becomes 3. Now the value of I is 3 and it checks if 3 is less than 12. Condition is true. Then it prints three. Now Python keeps executing block of for loop. As long as the condition remains true. Now when the value of i becomes 12, Python checks if the 12 is less than 12. This time condition is false. 12 is not less than 12. It is equal to 12. So as soon as the condition is evaluated to false, Python will not execute the block of for loop. The loop terminates right here. As soon as condition is evaluated to false, the loop terminates here. The control moves out of the for loops structure. That's why we have numbers being printed up to 11. in the range when you specify the second number, Python doesn't include that number. So in the background, Python does something like this. Whatever number you specify minus one. So Python generates sequence from 1 to number that you specify here minus one. So that's how guys the for loop works. Now let's say I want to print hello world 10 times. Just write hello world. As you can see now it has printed the hello world 11 times because loop starts from one and it keeps running as long as the value of i remains less than 12. So 1 to 11. So it has printed the hello world 11 times. Now the reason it has printed uh the hello world 11 times because this block of for loop gets executed 11 times. When this loop runs for the first time, value of i is one. So python checks if i is less than 12. Condition is true. So it executes the hello world for the first time. Now control goes back to the for loop. Value of i becomes 2. It checks if 2 is less than 12. condition is true. Now it executes the block of uh for for the second time. So it prints hello world for the second time. So it keeps executing the block of uh for loop as as long as the condition remains true. Now let's uh print I alongside hello world. As you can see now we are printing hello world alongside the value of i. Right? print. Let's write one more uh print statement for loop at work. Now this time in the block of for loop we have two print statements. So on each run Python is going to execute these two lines as long as this loop keeps running. Right now, just like the if statements, the block of for loop is determined by the first line that you immediately write after the for loop. Since first line is using four spaces as indentation, rest of the lines in the block of for loop must also follow the same level of indentation. Then they will be considered part of that for loop's body or block. So guys, that's how the for loop works. We are going to continue where we left off in the previous video. In this video, we will uh explore the for loop in a bit more detail. In the previous video, we just understood the working of of the for loop. Right? So write for i in range. This loop uh will print numbers from 1 to to 11. So I this is for loops variable. So let's uh execute the code. We have the numbers being printed from 1 to uh 1 to 11. Right? This range function generates the sequence from 1 to 12 - 1. So number that you specify here, the loop runs up to that number minus one. Right? That's how it works in the in the background. So when this loop runs for the first time, the value of I becomes one. It is initialized to one. Right? So the role of in keyword is that uh it takes the value that the range function generates then put that in the I variable. So when this loop runs for the first time, in keyword takes one which is the initial value, stores it in the i variable, then we are printing it here. Then on the second run we are incrementing the value of i by 1. Current value of i is 1. So 1 + 1 becomes 2. So the in keyword takes that value stores that in the i variable. Then we are printing here. Now what happens if we don't specify the increment value? As you can see we still have the same output. This is because by default the Python increments the value by one. One is the default increment value. As you can see it is working the same without specifying it. Now we can specify a specific number as well. For example two. This time the the value of I will be incremented by two. So let's execute the code. we have a different output right. So when this loop runs for the first time value of I becomes one. So we are printing one. On the second run the value of I gets updated right? The current value of I is 1. Now increment value is two. Right? So 1 + 2 becomes three. So the three gets stored in the I. So we are printing that down here. That's why we have three. On the third run, the current value of I is three. The increment value is 2. 3 + 2 becomes five. So we are printing that here. Right? So it keeps repeating as long as the value of i remains less than the value being specified here. Okay? So guys, use the third value only if or when you need to increment by a specific number. If you want to increment it by one, then you can leave it uh like this. By default, it increments by one. And we also do not need to specify the first value or the initial value. Let's execute the code. This time we have a slightly different output. We have numbers being printed from 0 to 11. Now here if you do not specify starting value and increment and you only specify a number like 12 by default Python starts with loop with zero. As you can see the loop is starting from zero. So when this loop runs for the first time value of i is initialized uh with zero by default then we are printing that here by default it increments the loop by one. So it keeps repeating until the condition becomes false. So guys, that's how the So that's how the range function works. And of course, if you want your loop to start with a specific number, then yeah, you have to explicitly specify that number here separated by comma. This time I'm telling range function that the loop will start from one and run up to the number specified here. this time loop will start from one. So that's how the range function works. In this video we are going to create a table using a for loop. This way uh it will increase or strengthen your for loops understanding. So let me quickly write the code 1 to 11 print. So I which is the for loops variable I multiplied by two. So let's execute the code and see what we get in the output. As you can see we have the table of 2 2 4 6 uh up to 20 right. So what is happening here? So when this loop runs for the first time value of I is initialized with one. So down here I am doing uh this multiplication the current value of I is uh 1. So 1 multiplied by two is two. So we have two in the output. Now when this loop runs for the second time the value of I becomes two because we are incrementing it by one right now while current value of I is 2. So here I'm multiplying the current value of I which is 2 2 into 2 4 on the third run value of I becomes 3. So I'm multiplying 3 into 2 which is 6. We are printing this table up to 20. So this loop ends at 10. So when the value of i becomes 10. So 10 into 2 20. That's the last output. When the value of i becomes 11, python is going to check if 11 is less than 11. Condition is false. So this loop terminates right here. So guys, that's how you can you know utilize the for loop to create tables. Now let's uh actually you know format this and uh um make our output more presentable and logical. So I'm going to use the f string. So here within parenthesis sorry curly braces I into 2 equal to now within the parenthesis write the mathematical expression I into 2 and let's uh check the output now this time we have a much better output okay let's create space is on the both sides of the equal to sign also create spaces here for a better output or formatting. As you can see now we have a much better output. So let's break this down. When this loop runs for the first time the value of i gets initialized to one. The value of i is one. Now here inside the f string I'm printing the value of i. The current value of i is one. So it prints this part one. Then here it prints this uh multiplic multiplication sign as you can see. Now here two I'm printing two as you can see two. It prints it as it is right. then equal to it is printing equal to then within the parenthesis I have sorry curly braces I have written this mathematical expression so here I am multiplying I current value of I is 1 I'm multiplying it with two so current value of I multiplied by two is equal to two on the second run value of I becomes two so it prints two it prints this part as it is then it multiplies 2 into two so we have four. So guys, that's how we have formatted this output. I hope you have a bit deeper understanding of the for loop. So that's it for this short video. In this video, we are going to learn about the break statement. The break is used to stop or exit out of a loop. Typically, a loop keeps running or executing its block as as long as the condition is true. Right? However, there are certain cases where we need to exit out of a loop early when uh a specific condition is met. Meaning, we don't have to keep running the loop until the condition becomes false or we want to stop execution once a task is complete to avoid unnecessary iterations. Using the break statement, we can make our script more efficient by allowing controlled exits from loops. Now let's dive into the practicals. I'm going to create a simple loop that will print uh let's say 10 numbers. So for i in range the loop will start from 1 and run up to the number 10. Now 10 + 1 write 10 + 1 colon print. Now print the loops variable which is I. Let's execute the code and we have the expected output. Right? Now next thing that I want to do is exit the loop when it reaches at a certain uh number. For example, when this loop reaches at uh number five, then I want to exit or teri terminate this loop. I don't want uh to print rest of the numbers or I don't want to continue the iteration after five. This is actually simple. We just need to implement the break statement. So if space now write the loops variable which is I if I equal to now specify the the number where you want to stop the loop at. For me it is going to be five six. In the if statements block write break. Let me execute the code. As you can see we have the expected output. Right? We are printing numbers only up to six. After it uh we don't have anything being printed because loop gets terminated after six. Let's see how uh let's break this uh down. This loop starts from one. So when this loop runs for the first time, the value of the for loops variable which is i is initialized with one. So the current value of i is one. When this loop runs for the first time down here, we are printing the current value of i which is 1. So we have one in the output. In the if statement, I'm checking if the current value of i which is 1 is equal to six. Obviously condition is false right? 1 is not equal to six. Since this condition is evaluated to false, the block of if will not be executed where we have the break statement. Now control moves back to the for loops uh structure. Now the value of i gets incremented by one. Now value of i becomes two. So here we are printing the current value of i which is two. Again here I'm checking if the current value of I which is 2 is equal to six. Condition is false. Therefore the block of if will not be executed. Now Python keeps repeating uh these steps until the value of I becomes six. So when the value of I becomes six down here we are printing the value of I which is six. So six gets printed. Now in the if statement here I'm checking if the current value of I which is 6 is equal to six. Condition is obviously true. Six indeed is equal to six. Now once this condition is evaluated to true the block of if gets executed where we have simply written the break statement. Now as soon as the break statement is executed, Python exits out of the loop or it terminates the loop. Control immediately moves out of the for loops uh block. Right? It will not print rest of the numbers or it will not complete the iteration or loop which starts from 1 to 10. Okay? Loop immediately stops at six. the control immediately moves out of the for loop as as soon as the value of I becomes six. Let me actually uh write a print statement outside of this for loops block. Hello there. As you can see after six we have the hello there uh being printed. So that's what happened when the value of I became six condition was evaluated to true the break statement was executed and when break was executed it immediately exits out of the loop loop was terminated right there then the execution continued after the for loops block. So it executed this line which is uh written outside of this for loops block. That's why the break statement is useful. Sometimes we don't have to, you know, run the complete loop. When a certain condition is met, we can exit out of the loop. Now, without the break statement, this loop will keep running from 1 to 10. It will complete all its cycles as long as uh the condition remains true. Okay, let me write uh the print statement uh within the if statements block. As you can see the loop stops at six. Right? So when value of I became six, the block of if was executed where we are writing this print statement and printing the value of I which is six. After it we have the break statement. So as soon as break was executed the loop terminated right there and control immediately moved out of the for loops block and it executed the line that is written outside of the for loops block right hello there as you can see now what happens if I uh change six to let's say three this time the loop exits at three right in this video we will Take a look at the continue statement. The continue statement is used in loops to skip the current iteration and move onto the next one. Let me simplify this. When Python executes the continue statement inside a loop, it will skip the rest of the code or remaining lines of code in that loop block and move onto the next iteration. Now, let's dive into the practicals. I'm going to create a simple loop that will print uh numbers from 1 to 10. Now let's print the for loops variable which is I. And this loop will print numbers from 1 to 10. As you can see, as expected, we have the output. Now, next thing that I want to do is skip a particular number. For example, I I don't want to print the number six. I want to print all these numbers except for the number six. So if you want to skip a particular number or iteration then we use something called the continue statement. Let's see how we can do that. So if first we have to check when the value of i becomes six. This is the number that we want to skip. So if value of i equal to 6 then simply write the continue statement inside the block of the if statement. Now we also need to print the for loops variable which is i. Make sure that the print function is written outside of the if statements block and inside the for loops block like this. Right? Let's execute the code. As you can notice guys, we have the expected output. So after five, we have directly seven. Six is missing. So let's see how it happened. So this loop starts from one. So when this loop runs for the first time, the value of i is initialized with one. And here I'm checking if the current value of i which is 1 is equal to six. Condition is obviously false. Since this condition is evaluated to false, the block of if will not be executed where we have written the continue statement. So this block will not be executed. Now here at line number five, we are printing the value of I which is uh one. The current value of I is one. So one is being printed. Now control moves back to the the for loop. The value of I gets incremented by one. Now it becomes two. Again, Python checks if the current value of I which is 2 is equal to 6. Condition is false. Therefore, the block of if will not be executed. And down here we are printing the value of I which is two. So it gets printed. Now Python keeps repeating uh this process until the value of I becomes six. So when the value of I becomes six here Python checks if the current value of I which is 6 is equal to 6. Condition is obviously true right six indeed is equal to six. So when this condition is evaluated to true the block of if gets executed where we have uh written the continue statement. Now as soon as the continue statement gets executed, it will skip the current iteration of the loop. Now skipping the current iteration of loop means it will not execute any code that is written after the continue statement inside a loop. Right? So after the continue statement we have uh the print uh function that is printing value of I. Now current value of I is six. That's why the six is missing because when the value of I became six the continue was executed and when continue got executed it skipped all the code that is written after it within this for loop after it obviously is print statement that prints the value of I. So I was not executed. So that's how the continue statement works. It doesn't exit the loop like the break statement does. it just skips the current iteration or cycle. So any code that you write after the continue statement inside a loop that code will not be executed. It will ignore that code and control immediately moves back to the for loops structure. Now the value of uh I gets incremented by one. It becomes 7. So here I'm checking if the current value of I which is 7 is equal to 6. Condition is obviously false. This time the block of if will not be executed. The execution remains normal. Now it will execute the print statement where we are printing variable I whose current value is seven. So it gets printed. Let's say three. This time it is going to skip three. Right? Because when the value of i becomes three, the continue gets executed and it will not execute any lines of code that that you have written after it within within uh within a loop. In this video, we will take a look at the while loop. While is another type of loop available in Python as well as in most programming languages. The y loop is similar to the for loop but it works a bit differently. Just like a for loop, a Y loop typically involves three part initialization, condition check and increment. However, the main difference between the two is in how these parts are structured. In a for loop, all three parts, initialization, condition check, and increment are usually written together in a single line or structure within the range function. Right? In a while loop, they are separated. Initialization is done before the loop starts. The condition check is written in the while statement itself. So increment can be placed anywhere inside the loop block depending where you want it to execute. Now let's dive into the practicals and write our while loop. First we need to initialize the Y loop. So I =0. The Y loop will start from zero. Now write the while keyword. Here we need to tell the Python how long this while loop will run. Space I less than 10. So this loop will start from zero and will keep running as long as the value of I remains less than 10. So in the while we have to specify the condition how long your loop will run. Now write colon. After the colon the block of while loop starts just like the for loop. A while loop also has its own sound block which is defined by the indentation. Press enter. As you can see it has automatically inserted four spaces. For some reasons if it doesn't add indentation or four spaces then write the four spaces manually. 1 2 3 four. Four spaces are the default indentation. Now I'm going to print the value of I. Now last part is increment. Increment is always specified at the end. So I'm going to increment the value of I by 1 + 1. Okay, let's execute the code and uh see what we get. Okay, we have the output from 0 to 9. So let me break this down. So here this is called the initialization. First we need to initialize the the y loop. So I this is the y loops variable and of course you can give any name to your variable. So this loop starts from zero. Now here I'm uh specifying the condition. So i less than 10. So this loop will keep running as long as the value of i remains less than 10. The current value of i is 10. Sorry, current value of i is zero. So, Python checks if the value of I is less than 10. So, 0 is less than 10. So, condition is true. So, when the condition is evaluated to true, the block of while gets executed. Here we have written print uh statement. So, it prints the value of I which is zero. So, it prints zero. Now, at line number four, this is called the increment where we increment our for loop. So I = I + 1. Current value of I is 0. So 0 + 1 becomes 1. Now 1 is stored in the variable I. So value of I is updated. Now control again goes to the Y loop. Here it checks the current value of I which is 1. 1 is less than 10. Condition is true. So it prints one. Now value of I is incremented by one again. Now current value of I is 1. 1 + 1 becomes 2. So again it checks if 2 is less than 10. Condition is true. It prints true. So it keeps repeating this block as long as the condition remains true. Now when the value of i becomes 10. So here Python checks if the current value of i which is 10 is less than 10. Condition is false. 10 is not less than 10. It is equal to 10. So condition is evaluated to false. So when the condition is evaluated to false the while loop terminates here okay it will not ex execute the code that you have written in the block of while. So that's how the while loop works. First we need to initialize it. Then we need to specify the condition how long you want to run this while loop. Then at the end we have to increment or update the while loop. increment part is always specified at the end. So let's uh execute hello world. Now this loop runs 10 times. So it executes the hello world 10 times. As you can see this loops sorry. Yeah this loop runs 10 times from 0 to 9. Now you can also write uh less than equal to 10. This time it will print numbers from 0 to 10. As you can see because here we are using less than equal to. So when the value of i becomes 10, python checks if the current value of i is 10 or current value of i which is 10 is less than equal to 10. Right? First it checks is it less than 10. Condition is false. Then we also have specified equal to. So it also checks if the 10 is equal to 10 condition is true. Since condition is true, so block of while gets executed. So it prints 10. But when value of i becomes 11, the condition gets evaluated to false. 11 is not less than equal to 10. So the y loop terminates here. So guys, this is the main takeaway for the y loop. First we need to initialize it. Then we need to specify a condition how long you want the while loop to run. And the increment part is always specified at the end. However, the increment part it doesn't always have to be at the end. Typically, it is written at the end, but you can place it uh anywhere you want inside the block of y loop like this. It also works like this. But it will change the uh output slightly. As you can see, for the most part, it is uh written at the end. But in certain cases, you might need to write it at the beginning or middle. This time, as you can see, it has changed the output slightly, right? Even though the loop starts with zero, but it is not printing zero, right? It is printing from 1 to 11. Why? So when this loop runs for the first time here the current value of I is zero. So Python checks if 0 is less than 10 condition is true. Now here at line number three we are incrementing or updating value of I. So I whose value is 0. 0 + 1 becomes 1. Now current value of I is updated to one. So here we are printing one. Right? As you can see. So zero never gets printed. Now here we have an unusual thing right? Even though this loop runs only up to number 10 but it is printing 11 as well. Why? So when the value of I becomes 10 condition is true right? I is less than equal to 10. Now add line number three. I we are incrementing the value of I by 1. So current value of I is 10. 10 + 1 becomes 11. So we are printing 11 here. Right? Now control goes back to the for loop. Now value of i is 11. 11 is not less than equal to 10. So condition is evaluated to false. So the loop terminates right here. So guys, that's how the loop works. In this section, we will explore functions. They are a fundamental concept in programming because they offer two major benefits or features. modular code and code reusability. Let's start with modular code. Modular code means breaking down a large program into smaller independent units or sections called functions. This makes the software easier to develop, maintain and update. Until now, we have been writing code line by line which works fine for small programs or applications. But when your code grows into hundreds or even thousands of lines, it becomes harder to manage. Without modularity, large programs can become messy and difficult to maintain. That's exactly what functions help with. Functions allow us to break a large program into smaller manageable sections by dividing it into multiple functions where each function is responsible for a specific task. For example, let's say you are building a calculator that can perform multiple operations such as addition, subtraction, multiplication, and division. Without functions, all the code would be written sequentially in a single block which makes it hard to read, maintain and update. Now with functions, each function can be written in its own block or section. We can create one function for addition, one for subtraction, one for multiplication and so on. This approach makes your code cleaner, more organized, and easier to debug and expand later. Most importantly, once you create a function, it can be reused throughout your program. This is known as code reusability, which simply means you can use the same function multiple times, avoiding the need to write duplicate code. Now, let's dive into the practicals. So write def. The def keyword is used to create or define functions. Space. Now give a name to your function. I'm going to create a simple function to add numbers. So I'm going to give my function name add. And of course you can give any name to your function. Now write parenthesis. Parenthesis are important. That's how Python recognizes a function. Now write colon. Colon is important. Colon basically tells Python that after it the body of this function starts just like other control structures like loops, if statements have their own bodies, a function also has its own body. The code that you write inside the body or block of a function. That code gets executed when you call or use a function. And how do you define body of a function? Well, it uses indentation to define body or block of a function. Press enter. As you can see, it has automatically inserted four spaces. This is the indentation, right? And for some reasons, if your code editor is not inserting four spaces, then you can add or insert them manually. 1 2 3 four. Four spaces are the default indentation in Python. Now let me write a print statement. Sum is add two numbers. Okay, let's execute the code and we should have 79 in the output. However, here we don't have any output at all even though we have created this function. Right? Well, here we have done the first part. We have created or defined this function. Now to use a function, we have to call it. How do you call a function? Outside of the block of this function, write the exact function name that you want to call. For me, it is add. So here down here, write add. Then parenthesis. Parenthesis are important. So when you call a function, then Python is going to execute the code that you have written here. This time we should get the output here sum is 79. So we have the expected output. So this part at line number five this is called calling a function. Calling simply means using a function that you have defined and this is called the function definition. In the function definition part we define functionality for a function. What your function actually does. In in my case, my function is simply adding these two numbers. That's how the functions work. Now, one thing that you must remember is that function must always be called below its definition. You can't call a function like this above the definition like this. As you can see, add is not defined. So function must a function must always be called below its definition outside of its block of course like this. Now the best thing about functions is that once you create a function then we can reuse that function as many times as you like. Okay, let's uh uh add a few more print statements inside the block of this add function inside the body of uh add function. Now these two lines as you can see they are using the same level of indentation. So these two lines exclusively belong to this add function. So when you call this add function these two lines will be executed because they belong to this add function as you can see right print is is now we have these three lines that are part of uh this function they will be executed when I call it as you can see. Now the best thing about functions is that uh they are reusable. What it basically means once you create a function you can reuse it as many times as you like. So let's reuse this function add. As you can see we have uh reused this add function successfully. Right? So at line number six when I called the function Python executed this uh add function. Right? And uh it printed all the lines written inside its body. And line at line number eight, I called this function again. Then it uh executed this function and executed all the lines uh written inside its block. This way you can reuse a function as many times as you like. You just need to call it like this. Okay. Now we have uh called this function four times. So it will be executed four times. This is a very convenient way to avoid writing repetitive code. Right? Without functions we would have to write the the same code again if it is needed in our program. Right? With functions we can just create a function once then use it as many times as we like. Now let's create a few more functions for better clarity. Now I'm going to create a function to multiply numbers. Rent is define division. Let's uh execute the code. As you can see, we have sum even though we have uh created or defined two more functions division and multiplic multiplication but we have no output for these two functions because we have defined these functions but we have not called them yet. So let's uh call the multiplication function. As you can see multiplication function write the function name as it is. Now we have multiplication here. Let's call the division function. As you can see division is this. So we have defined these three functions. Then we we are calling them. Right now functions are executed in the same order as you call them. For example here I I have first called the add function. Python is going to execute this add function first. Then I have called the mult multiplication function. It will execute uh the multiplication and at the end we have this division function. It will be executed at the end. Let's put it at the top. Now we have changed the order of execution. This time the division function will be called first then add and multiplication as you can see. So guys that's how you can create and call functions. Now what uh you are going to do is u create two more functions. As you can see I have created functions for add, multiplication, division but I have not created functions for subtraction and modulus. So what you are going to do is create functions for modulus and subtraction. Just define them then call them. It should be easy. So that's it for this video guys and of course if you come up with any problems you can let me know in the Q&A section. In this video we will discuss arguments and the difference between arguments and parameters. Arguments are essential components of functions in programming. Without arguments, functions would not be as flexible or powerful. Arguments allow us to pass data into a function. The values or data passed into the function are called arguments. Once you pass arguments to a function, then the function can use uh those values to perform tasks. Let's say you want a function to add two numbers. For the function to perform that calculation, it first needs the two actual numbers. This is where arguments come in. By using arguments, we can pass the required values into the function. The function then takes those values, processes them, and returns a result. Parameters are the variables that receive values in the function definition. Now, let's dive into the practicals. Let me quickly create a function add. Let's add two numbers. and let's call the function. Let's execute the program. Okay, we have the expected output, right? That's how we have been working with functions so far. We define a function, then call it. Now, we are going to make it interesting. We are going to pass arguments to a function. Now, how do you pass arguments to a function? Well, inside the parenthesis, write u uh any two numbers. Let's say 12 and 89. Now these are basically called the arguments. Arguments are nothing but the data that you pass to a function. So I'm telling this add function take these two numbers or arguments then give me their sum. Now once you pass data or arguments to a function those arguments must be received where we have defined the function. Now this add function is being defined here at line number one. Right? Now inside the parenthesis of this add function we must receive these two arguments. Once we receive arguments then we will be able to use these values inside uh the definition of this function. How do you receive arguments? Well, simply write the variable names a comm, b. Now these variables are specifically called parameters. Parameters are the variables that you define or list inside the parenthesis of a function definition. First argument gets stored in the first parameter or variable. Second argument gets stored in the second variable. Now let's print value of these variables. A okay let's use string formatting. A equal to A, B= B. As you can see guys, a equal to 12 and b equal to 89. So I passed 12. It was received by the parameter or variable a. As you can see a equal to 12 and second argument was stored in the second parameter b then we are printing its value. So we are receiving the the arguments successfully. Now once we receive the arguments then we we can use them however we like. So what I'm going to do is uh add these two numbers. Sum is a + b. Okay. Sum is a + b. So we have the expected output. Right? We are adding a + b. These two variables are storing the data that has been passed as an argument here. Right? First value gets stored in the first variable. Second value gets stored in the second variable or parameter a b. Now we are using these two variables inside the function. Now let's uh pass third argument 67. Now the arguments must be separated separated by a comma like this. This time we have passed these three arguments. Now when we pass three arguments then all the three arguments must be received inside the function definition like this a b c. If you don't then it will throw an error as you can see add takes two positional arguments but three were given. So let's receive this as well. C. Now C is holding the third argument and now we have the expected result. Now the best thing about arguments is that we can pass different arguments to the same function. So let's call the add function again. This time I'm going to pass different arguments or values like this. As you can see, we have called this add function twice, but we have passed different values to the same add function. That's the beauty of functions combined with uh combined with arguments. We can also pass other type of data. It doesn't have to be numbers. We can pass uh strings, decimal numbers as well. So, let's create another function that print names. print names. Print name. I'm going to pass Sunny, Dimalu. Let's define the print name function. Print name. Now, as you can see here, uh I'm calling this print name function and and passing these two string values as as arguments. Now these arguments must be received inside the parenthesis of this print name function. So a b okay let's uh give some meaningful variable names f name last name print first name is f name last name is last name l name. Let's execute the code. As you can see, first name is Sunonny, last name is Timalu. Right? So, we have created two functions add and we are passing the numbers to it and I have also created print name function and I'm passing string values to it or string arguments to it. then receiving them here and utilizing the arguments being passed to the print name function. Now we can also use variables as arguments right for example a equal to b equal to this c equal to this. Now instead of directly passing values I can pass these variables as an arguments right. Yeah, this is pretty much the same here. Instead of passing values directly, I'm passing these three variables. And of course, these two three variables are storing the numbers, right? A= 12, B= 6, 7, and C= 9 0. So I'm sending them as arguments. Variable A which is storing 12, it gets stored in the A variable. Second value gets stored in the B. Third value C which is holding 90, it gets stored in C. So let's execute the code and we have the expected result. Before we dive deeper into functions, it is important to understand variable scope because it plays an important role in writing clean and error-free code. Variable scope defines where a variable can be accessed or modified within a program. It is determined by where the variable is created. In Python, there are two primary types of variable scope. Global scope and the local scope. A global variable can be accessed from any part of the program including inside functions and outside of function. Global variables are created in the main body of the script or program and outside of any function definition. Now a local variable is a variable that can only be accessed within the function where it is declared or created. It can't be accessed outside the functions block where it is defined. Now let's dive into the practicals. We are going to start with uh the global variables. Let's create a equal to 56. And I'm going to also create a a function print. Let's access this a variable inside this add function. Inside the add function a equal to a. Let's call the add function and let's access the same variable a outside of uh the function as well. Outside of the function a equal to let's execute the program. Okay, it is working as it should. So what basically is happening here? This a equal to 56. This is a global variable. A global variable is is a variable that is created outside of a function. Right? This a as you can see it is created outside of a function. So when you create a variable outside of a function that variable by default becomes the global variable. A global variable can be accessed by anyone and anywhere in your program. So here we have accessed this a variable inside this add function as well as outside of a function as well. Right? So that's the global variable. All the global variables that you create outside of a function by default they are the global variables and remains accessible to everyone inside a program. So this is as simple as that. Now let's move on to the global variables. Sorry, a local variables. A local variable is always created inside a function. So inside the add function, let me create x= 89. Let's access x print x = x. Right? Okay. Here I'm able to access the x as you can see x equal to 89. Like I was saying a local variable is created inside a function. You don't need to perform any additional steps to create a local variable. So when you create a variable inside a function that variable automatically becomes a local variable. A local variable is only accessible within the function where it is created. Right? This X as you can see it is created inside the add function. Now it can only be accessed within this add function. If I attempt to access it outside of add function or in other functions then we won't be able to access it. So let's print x equal to x and we have an error as you can see x is not defined right even though the variable x as you can see it is being created here but it is not accessible outside of this function a local variable can only be accessed by the function where it is created right the this is a as you can see this is a global variable I'm able to access it inside the add function as well as outside of uh the add function as well whereas this local variable x I'm able to access it here inside the add function but I can't access it outside of the add function now so scope of a local variable remains within the function where it is created So let's see how we can make a local variable uh global. We have the global keyword to make a global variable uh sorry local variable global. First we need to uh define the variable global x equal to 78. Let's execute the script and we should have an error. As you can see at line number four four we have an error global x= to 78. Now if you want to make a local variable global first we have to declare that variable. You can't assign the value in the same line like this. First declare it like this global x then assign a assign a value to it in a new line like this. Now it is working just fine. As you can see I am able to access X here inside the add function as well as I am able to access the same X variable outside of the function as well. So if you want to make a local variable global then we need to use the global keyword. Let me remove the global keyword. Now we have an error. As you can see X is not defined at line number 11. This X is accessible to to the add function at line number six. Right? But after removing the global keyword, the same X variable is not accessible outside of this function. So let me write the global keyword again. Global X. Now we have made this X a global variable. Now it will be accessible outside of this function as well as you can see. So that's the difference between global and local variables. Now understanding variable scope like global and local is extremely important. Without proper scope control programs become difficult to manage and debug. You should not make a local variable global unless you have a very specific reason to do so because once a variable is global, it becomes accessible everywhere in the program. This means that it can be modified or overritten by different functions or even from outside any function which can easily lead to unexpected behaviors and bugs. So again, don't make a local variable global unless you have a very specific reason to do so. Let me remove the global keyword. Now if let's say if I create another function and uh create the same variable x x equal to this. Now I have the same x variable in the two different functions. Well, these two are totally different variables. They are independent variables. This x is a separate variable that belongs to add function. This x is a separate variable that belongs to to multip this multiplication function. In this video, we will discuss the return statement in Python, which is a fundamental concept when working with functions. The return keyword allows a function to send a value back to the part of the program that called it. In simple terms, the return statement sends the result or value back to the place where the function was called. This allows the result to be stored in a variable. You can also print the result or use the data or result in further processing. Now let's dive into the practicals. I'm going to create a simple function that returns sum of two numbers. So add let's return sum of 34 + 44. Let's call the function and execute the code. Okay, we don't have any output. This is because we have not printed uh any value yet. Right now here I'm using this return keyword or statement. Now the return basically returns a value to the part where a function has been called. It returns sum of these two numbers to the part where you have called this add function. Okay. So when return gets executed, it sends the sum of these two numbers to the add function wherever you call it. Now once a value is sent or returned to a function then we can utilize that value. We can simply print that value like this. Okay, as you can see 78, right? So return sent the result of these two numbers to the part where this function has been called. It is being called here at line number four. Once a value is returned to a function then we can print that value like this add function. Now the recommended and standard way of dealing with uh a returned value is to store that value in a variable because once you store a value in a variable then that value can be reused later in the program. So a equal to add. So let's print a. So we have the same result 78. So what basically is happening here? The return statement returned sum of these two numbers to the function where it is being called. It is being called at line number four. When the value was returned to it, we are storing that returned value in the variable A. Then we are printing that variable A. Right? So we have the 78 as an output like this. Let's modify it a little. So that's the basic working of the return statement. Uh what we are going to do is uh create variables A B C = A + B. Now I'm returning C. As you can see we have 112. So this time I have created variables A B and then adding these two variables and storing that result in the variable C. Then I'm returning the variable C which is storing the sum of these two numbers. Right? Now when the Python executes the return statement, it does not execute anything that is written after the return statement. For example, if I write the print statement after return, Python will not execute this line at all. As you can see, it has not been executed. So, as soon as the return gets executed, the execution stops right there. Okay, it returns value to the part where the function has been called and it will ignore all the lines of code that you write after it. Those lines will not be executed. Now, one thing that I want to clarify that the return does not stop execution of the entire program. It only stops the execution of the function where you use the return keyword. Right here after executing the return statement, Python will stop executing any lines that you write after it. Now you can also return string values like this. Let's say sunny. Now this time it is returning the sunny to the add function. Then I'm storing that in the a and printing it. Right? Let's use arguments. So what I'm going to do is uh I'm going to pass these two arguments to the add function. Let's receive them. And uh let's return a + b. store that result in a sum print sum and we have the output here. So what is happening here? I'm passing these two values as an argument to the add function and receiving them here. And then I'm adding these two values. And then return statement is going to return the sum of these two numbers to the add function where it has been called. It has been called here. Now the value that is has been returned gets stored in the sum variable. And down here I'm printing the sum. So that's how guys the return statement works. It will get clearer as we progress in the course. In this video, we will create a mini project. We will build a calculator. The goal of this project is simple. We want to apply everything we have learned so far and use it to build something useful. We will apply concepts such as type casting, functions, conditional statements, and more. The program will ask the user to enter two numbers. Then the user will choose the operation they want to perform such as addition, subtraction, and others. Based on the user's choice, the program will perform the selected operation and display the result. Now let's dive into the practicals. First thing that we are going to do is allow users to enter two numbers. Then we will perform calculations based on their choice. So num one variable is going to store the first number that user enters. Let's copy and paste it. The num two variable is going to store the second number that user enters. And of course we need to perform type casting. We need to convert user inputs into a number. As we already know, by default the input function treats all inputs as string. So to perform calculations, we must convert strings into numbers. We can use float or integers. I'm going to go with integer. So int parenthesis. Now close the ints parenthesis at the end like this. Repeat the same thing for uh second input. Let's execute the code. Okay, it is working just fine. Now, next step is to display a menu to user. Right, we are going to display a menu that will give the users the option that they can select from or menu item that they can select from print. So one is for uh addition. Let me copy paste. Two is for uh multiplication. Four is for subtraction. Let's execute the code. Enter first number, second number. As you can see, after user enters these two numbers, then we are displaying this menu to the user. Right? User can select these operations. For example, if user wants to perform addition of these two numbers, then they can select one. If they want to multiply, then they can select two, three and so on. Now next thing that we need to do is store the user's choice. Right now my program is not allowing user to enter their choice right to what operation they want to perform. So let's create a variable called choice equal to input. So enter enter your choice. Let's execute the code. As you can see now we have the options. This is the menu that a user can select from I want to perform addition. So I'm going to enter one. As you can see I'm able to enter one. So whatever value the user enters that value gets stored in the choice variable. Now using this choice variable we can perform the calculation based on user's choice. Before we proceed further, make sure to have space after choice like this. This way it looks better and uh user experience will be a much better as you can see. Enter choice. Now we have a much better formatted output. Now let's write functions for each of these functionalities. First we need to check the user's choice. So whatever user enters that value gets stored in the choice variable. So choice if user's choice is one then we are going to perform addition. So what I'm going to do is uh call the add function pass num one and num two as arguments. Now the num one as you can see num one stores the first number that user enters. num to stores the second number that the user enters. We are passing these two numbers as arguments to the add function. Now we need to define the add function. Define add. Now receive the arguments. The first arguments num one gets stored in A. Second arguments get gets stored in B. Now let's uh add the numbers. Addition is a + b. Sorry after the closing quote. Write comma. Now let's test the code. Enter first number. Now I'm going to enter one which is for addition. Okay. We don't have any output. It should have printed this addition. Okay. Okay. I got the error. Now this one needs to be surrounded by double quotes because because as we already know by default the input function treats all inputs as string and a string must always be surrounded by uh quotes like this. So when I enter one it is treated as string. So I'm comparing if choice which is storing a string even though I'm entering number but input function treats it as a string. So I'm comparing if string is equal to string. Now it should work. So what if condition is going to do? It will check if whatever user enters equal to one or not. If user does enter one then we are calling the add function. As you can see addition is 24. So let me quickly walk you through this uh this program again. So we have created two two variables. First variable stores. First number that user enters second variable stores. The second number that the user enters. Then we are displaying this menu to the user. Right? And based on this menu they can make a choice. Now the choice variable is storing the user's choice. Whatever choice user makes. So here as you can see user entered one. Now here I'm checking if choice is equal to one which is true because user did enter one condition was evaluated to true and we called the add function and we are passing the numbers that user enters as arguments to the add function and then here we are defining the add function and receiving the arguments then adding those numbers. Now let's create functionalities for other functions. If I enter two, as you can see, we have no output because we have not created function for the selection two. So here we need to use obviously else if if choice is equal to two. Then we are going to create the multi call the multiplication function. multifunction pass num one and num two as arguments. Let's define the multiplication function. Define multiplication a b print multiplication is a into b. Let's execute the code. Let's select two. As you can see multiplication is 124. So it is working as it should. Now let's check if user enters three. I'm going to fast forward this and copy the code. If user ch enters three, then we are going to call the division function and pass the values that user enters as arguments to the division function. Let's create the division function. Print division is division is a divided by 2 b and let's see if it is working 3. Okay, division is 4.0. So it is working just fine. And now let's create function for the subtraction. If user enters let's say or then we are going to call subtraction function and pass num one and num two as arguments. Let's create the function subtraction. Subtraction or difference is subtraction is a minus b. Let's enter four. Okay. Subtract positional parameter what were given to at line number 23. H subtraction. Okay. A B now it should fix the error. Okay. Subtraction is this. So it is working perfectly. So guys we have created functionalities for all four options. Now what if user enters five? Right? We don't have any functionality for five. So if user enters any other option then we are going to print an error message. Invalid choice. Invalid choice. Now as we already know the else statement is always written at the end. Right? When you have else if statements the else is always written at the end. And when none of the conditions match then the else gets executed. Let's uh execute the code. Let's enter six. As you can see, invalid choice because this value did not match to any of these statements or if conditions, right? We don't have any functionality for six. So six did not match to any of these conditions. So block of else was executed where we are telling okay this is an invalid choice. This program as you can see it allows us to perform these four operations. Now there is one fundamental arithmetic operation missing in this list that is the modulus. So what you are going to do is add that modulus functionality in your program. Right? I intentionally left that out. you are going to complete this by yourself. So what you are going to do is add the fifth item in this menu that is going to be the modulus and create functionality for that. It is simple just add option five or fifth menu item which will allow users to perform modulus. Then down here you are going to check if user selects five then you will call the modulus function and and then of course you have to define the modulus function. That's the homework for you guys and of course let me know if you come up with any problems. Lists are an essential concept in Python programming. Lists in Python work the same as arrays in other languages. A list stores multiple values in a single variable. As we already know, a regular variable holds or stores only a single value at a time. On the other hand, a list can store multiple values within a single variable. Therefore, a list variable is a special type of variable in Python where you can store multiple values or items. A list in Python is an ordered, mutable, and heterogeneous collection of items or elements. Let's break down each of these keywords one by one. Ordered means list item maintain their defined sequence and can be accessed using index numbers in that specific order. Okay, we'll explain it in more detail shortly using practicals. Okay, mutable means you can add, remove or modify items in a list after it has been created. Lists are also heteroggenous. This means a list can store different types of data. For example, your list can have integers, strings or decimal values in it. Now let's dive into the practicals. Write a a equal to. Now square brackets. Square brackets are extremely important. A list is defined using a square bracket. Inside the square bracket, we we can uh we can specify the items or values that that you want to store. So let's uh start with uh some numbers. So we have successfully created this list called a. This list as you can see it is storing all these items. Now these items are separated by commas. The list items or values that you put in a list, they must be separated by commas. Then they will be considered as separate values. So this is a single list variable and we have stored 1 2 3 4 five v values in it. So a single list variable is storing five values. Let's see how we can access a list. So print a. Let's execute the code. As you can see it is printing the entire list as it is. Right? In this list we have these many items and all of them have been printed. Now I want to access individual items. Right? Maybe I want to access 76. 76 only not uh this entire list. So how it is going to do that? Because we have a single variable that is holding multiple values. Well, Python uses something called the indexing. Using indexes, we can access individual items. Now, the index values are assigned automatically in the background by Python. The first item is always assigned index value zero. Second item 1 2 3 4. This is done automatically by Python in the background. The first item has index value of 0, second one, two and so on. These are called index values. Now let's say I want to access 76. Now what is the index value of 76? Two. So using its index value, I can access this 76. Now in the print statement, write square brackets. Within the square bracket specify the index number that you want to access. Let's say two. So write two. And we should have 76. As you can see 76. So that's how you create a list as well as access them using their index values. Now I want to access 787. So again a square brackets specify the index number. 778 is at fourth index. So four. As you can see, we have accessed these two items successfully. Using indexing you can access any list item. So in a list you can store as many items as you like or values as you as you like. It doesn't matter. These index values are automatically assigned by the Python. Just remember that the index values always start from zero. First item in a list will always have the index value of zero. Second item 1, third, two, and so on. Now let's create a list that stores string values. Fruits, let's say I have a list. fruit, apple, banana and uh cherry. Okay. So I have created another list called fruit. This is a list variable and it is storing these three values. Values must be separated by a comma. So now in a list whether you store string values, integer, floats or even if you mix them the indexing remains same. The first item in a list will always have the index value of zero. Second items index value will always be one and so on. Let's say I want to access banana. So first I have to tell Python the exact list name that you want to access fruits then square brackets within square brackets specify the index number I want to access banana index value of banana is one so we should have banana being printed so that's how the the lists work so in the next video we will learn how to loop through a list. In this video, we are going to loop through a list. Previously, we learned that we can access all list items at once or one by one using indexes, right? However, in many situations, we need to process every item in a list automatically and individually. This is where looping becomes very useful. By looping through a list, we can perform actions on each element without writing repetitive code. I will demonstrate it with with the a real world example. Now let's dive into the practicals. What I'm going to do is uh create a list called files and it will store some file names. uh let's say okay so we have created this list called files and it is storing these three items or values they must be separated by commas like this as you can see now what I want to do is loop through all the items that this list is storing I want to access them one by one so write for i in. Now specify the list name where you want to loop through. For me it is files colon print I let's execute the code then I will break down everything. As you can see we are able to access all the list items one by one. Now the way it is working is this for loop will loop through all the items one by one. The important part here is this in keyword. So the way in keyword works is it takes each item from the specified list one by one then store that item in the for loops variable which is which is i. So when this loop runs for the first time the in keyword takes the first item from this files list which is this then stores that in the i variable. Down here I'm printing the value of I. Value of I is backup. So it is printing backup. Then control moves back to the for loop. Now in keyword automatically moves to the next item in the list which is this. It takes this list then stores it in the I variable. So the old value that the I variable is storing which is backup.py gets overwritten by this new value autoupd.py. Now the current value of I is auto upd.py. Then we are printing that here. Then in keyword automatically moves to the next item in the list demo. It takes this item stores it in the I variable. Then we are printing that here. As you can see it has printed all the three variables. And when there is nothing more to iterate or loop through the loop automatically exits. Okay. the control moves out of the loop when there is nothing or no more items to loop through. So that's how the in uh works. It takes one item from the provided list one by one, then store those items in the loops variable one by one. This way we can access those items individually. Now let's say I want to check if this auto upd.py Pi file exists in this list or not. It is easy. So what I'm going to do is check if I what is I? This I is this loops variable which which stores these list items one by one. So if I equal to let me copy the exact thing that I want to compare against. print item found in the list and let's execute the code. As you can see item found in the list. So the way it worked is when this loop ran for the first time the in keyword took the first item backup.py stored it in the i variable. Now the i is storing backup.py. Here I'm checking if the current value of i which is backup.py pi is equal to auto upd.py. Now this condition will not match because backup.py is not equal to this. So block of if will not be executed. And in the next run the in keyword takes the second value stores it in the i. Now value of i is autoupd.py. It checks if autoupd.py is equal to autoupd.py. This time these values match. So once there is a match, Python executes the code written uh inside this if statement which is this. So it is printing this message. Now let's uh try to check uh auto upd 1.py. This time we don't have any output because this file does not exist in this list. It will not be able to match this file against any of these files specified in this files list. So guys that's that's how you can loop through lists. Looping through lists is extremely important. This way we can we can deal with each item individually one by one. So to summarize the in keyword acts as a membership operator and a connector. It tells the Python to look at a collection like a list or sequence and pick out each item one by one. In this video, we will learn how to manipulate lists such as adding new items to a list, removing items, modifying existing items, and more using list methods. Python provides plenty of built-in methods or functions that allow us to work with lists easily. These methods let us perform various operations on a list such as adding and removing items, modifying existing items, sorting ATC. Let's dive into the practicals. Let me create a list and I'm going to add these items to it. Apple. So I have this list called fruits and I have uh included these items in it. We are going to manipulate this list. I'm going to start by appending or adding a new item to this list. For example, I want to add blueberry to this list. Okay, the syntax is simple. First, write the exact list name that you want to update or where you want to append the item to. For me, it is fruits dot. Now, the method or function for appending item to a list is simply appendp within quotes. Write the item name that you want to include. Let's say blue berry. The way uh it is going to work the Python will append this specified item at the end of this fruits list. The append function adds item at the end. So let's print the complete list. As you can see, blueberry has been appended at the end of this fruits list. The original fruits list did not have the blueberry, right? But at line number three, using the append method, we appended this blueberry at the end. By default, append adds at the end. Now I want to add this blueberry at a specific location, not at the end. In such case, we have a method called insert. Okay, so fruits do.insert. So I'm telling Python that insert an item in this specified list called fruits. Now inside the inserts parenthesis we need to specify two things. First the location where you want to insert the item. I want to insert after apple. Okay. So index value of apple is zero. So if I want to append after apple, the index value will be one. So I'm telling insert at first index add blueberry. Make sure that index value is separated by the comma. As you can see we have successfully added the blueberry at second position or at the index value one. This way you can add at any location. Let's say three. As you can see, we have added at the third index 0 1 2 and three. At third index, we have added the blueberry. Now, let's see how we can remove uh items from a list. So first obviously we need to provide the list name where you want to remove the item fruits dot remove. Now within quotes specify the item name that you want to remove. I want to remove cherry cherry. So remove method is going to remove this cherry item from the list. If if this item does exist in this specified list, it will remove this cherry from this list. As you can see, cherry has been removed from the list. Right? This way you can remove any item, right? Just specify the exact list value that you want to remove. This time it will remove apple from this fruits list. As you can see, apple has been removed. We have another method for removing items which is pop. So fruits dot pop. As you can see it has removed papaya. By default the pop method removes the last item from a list. Right? In this uh list called fruits the last item is papaya. So pop method removed it. That's how it works. Now we can also remove list items by their index values. For example, I want to remove cherry. The index value of cherry is 0 1 2. So within brackets, specify two. It will remove the cherry. As you can see, cherry is no longer in the list. Let's remove zero. At zero, we have apple. It should remove apple. Now I want to remove all the items from a list. So write the list name fruits dotclear. Now the clear method clears or removes all the items from a list. So here I'm applying this clear method to this fruits list. So it will remove all the items from this fruits list. As you can see now we just have an empty list. Right? Another method that we have is called index. Now the index method returns index value of the specified item. So here I have provided apple item to this index method. So it will return the index value of this item. We are going to store that index value here. A equal to fruits dot index. Uh let's uh print A. As you can see zero apple is at zero position. So the way it worked is the index took the index value of apple then we are assigning that value to a and down here we are printing that value. Let let's go for let's say cherry and we have two cherry is at second position 0 1 2 right so that's how the index works then we have uh something called count the count method counts how many times an item is appearing in a list for example apple right so count method is going to count how many times times the specified list item apple is present inside the a fruits list. Again we need to assign the value to a variable. So count equal to this as you can see one. So the way it worked is count method counted how many times uh the apple is appearing in this fruits list. then stored that value in the count variable. Down here we are printing the value of count which is holding how many times apple is uh present in this list. We have one as an output. As you can see apple is present exactly one time. Now let's add another apple to verify uh the working of count apple and we have two right. So apple is present two times in this list. Now let's see how we can copy a list. We have this fruits list. Right? Now I want to copy this list or I want to copy all its items. So let's see fruits backup equal to. Now write the list name that you want to copy. I want to copy fruits. Then copy. Let's print fruits backup. As you can see, we have copied it successfully. So the way it worked is I'm providing fruits list to the copy method. So copy method is going to take all the items from the fruits or provided list then store those items uh in this variable fruits bk as list. Okay, it will copy all the list items then store them into this new list variable fruits BK. Down here I am uh printing the fruits BK variable, right? As you can see, it is holding the exact values that are present in this original fruits list. So that's it. Okay. Okay, I almost forgot the sort method. Before signing off this video, uh let's see how we can use the sort method. Fruits dot sort. Okay. Now, the sort method sorts the list items in ascending order from A to Z or lower to higher. As you can see, roots. Okay, we have an error. Fruits BK is not defined. Okay, fruits. Fruits. As you can see, it has sorted these items in the ascending order. Okay, let's add let me remove the apple and add maybe zen. So sort uh method is going to sort these items in ascending order from A to Z. As you can see, even though this list doesn't have sorted items, but after applying the sort method, it has uh sorted the list from A to Z. It can also sort numbers. Uh let's provide as you can see it has sorted these numbers that are in this list. So that's how the sort method works. Now let's see how we can uh sort items in reverse order from highest to lowest. Fruits dot sort. Now within parenthesis write reverse equal to true. Make sure that t of true is in uppercase. As you can see it has sorted in descending order. So that's it for this video. Tupils are a data type similar to lists used to store multiple items in a single variable. However, the main difference between a tupole and a list is that tupils are immutable. Meaning you can't change, add or remove elements after the tupil is created. uh tupils are often used when you want to store a fixed set of values that should not be modified or updated. The second difference is that tupils are defined using parenthesis whereas lists use square brackets. Right? Now let's dive into the practicals. I'm going to create a simple tupal. So a equal to parenthesis. The tupils are defined using the parenthesis. Inside the parenthesis, you can place your values 12. Now the values or items must be separated by commas like this. So we have uh successfully created the tupal called a and it is storing all these different values separated by by commas. Right now let me print the tupil a and we have accessed all the tupal items over the entire uh tupil. As you can see here just like uh lists the tupil are indexed means tupal items can be accessed using index their index values. Right? The first item in a tuple is automatically assigned the index value 0 second 1 2 3 and so on. Now if you want to access let's say 56 then we need to use its index value which is two. So after the tupal name which is a square brackets within square brackets specify the index index number two. At index number two we have 56. So it will print 56. As you can see this way you can access any tupal item using um using its index value. Let's access tupal item. Fourth item. At fourth item we have 787. And yeah that's how you can create and access tupils. Now uh let's see how we can loop through a tupole. Looping through a tupole is same as we looped through a list. Right? For i in now specify the tupal name that you want to loop through. For me it is a. Now print uh value of i. As you can see we have successfully accessed all the tupal items. Right? The way it is working is when this loop runs for the first time, the in keyword takes the first item that is stored in the tupal 12 and stores it in the variable i. Then we are printing that out. And on the second run, the in keyword takes the second value store that in the i variable. So we are printing I which is the second value is this and on the third run the in keyword takes the third value stores it in the i variable then we are printing that here. So this for loop keeps repeating as long as there are items in the tupole. So when there is nothing to iterate or loop through the loop automatically exits or terminates. Now guys, like I mentioned earlier, tupils can't be updated or modified, right? So if you want to modify a tupole, then we need to do the type casting that we will discuss in the next video. In this video, we will take a look at the tupole methods in Python. Unlike lists, tupils don't have dedicated methods for updating or removing items because tupils are immutable, meaning they can't be changed after they are created. You can't add or remove items in a tupole. However, there are situations where you may need to modify or update the data stored in a tupole. Since you can't directly add, remove or change items inside a tupole as you would with a list, you need to use a workaround. Let's see how we can update, modify, or manipulate a tupole. The only way to manipulate or modify a tupole is we need to convert it into a list. So once it is converted into a list then we can use list methods to manipulate it and then convert the list back to the tupole. Right? So here I already have this tupil here that is storing these items. Now I want to add a new item to this tupal. So step one we need to convert it into a list. So a equal to list. Now list is a function that is used to convert other data type into a list. Now within parenthesis specify the tupil that you want to convert into a list. Let me put a. Now what is a? A is a tupal right? So list is going to take this tupil convert it into a list then store that in a. Now a is storing the tupal that has been converted into a list. Now it it has become a list. So let's quickly check its type. As you can see now a is a list. If I use this print statement above the list function as you can see tupil. At line number two we are printing type of a. Here it is tupil. But at line number three I converted this tupil into a list. Now it is a list. Now once we convert it into a list, now we can perform any operation that we want. For example, I want to insert a new item at index 2 item after 44. So insert 3 78 print a. As you can see, I have inserted an item at the third index, right? 0 1 2 3. At third index, we have 78. This way, you can perform any any modification or manipulation with a tupal. Okay, you can use any list method that we that we want. Now, after modifying the list, I want to convert it back to the tupal. So a equal to tupal. Now the tupal function converts other data type like uh like list into uh tupal. So a now I have provided it the a. What is a? A is storing this list. Right? Now here I I converted this tupil into a list. Right? So a is now a list. Now down here after performing this insert operation I'm converting this a which is a list back to the tupole storing that tupil in the variable a. Now let's uh print the a. As you can see it is it has been converted back to the tupole. So guys that's how you can modify a tupil. That's the only way to modify a tupole. we need to convert it into a list then perform the desired operation then convert it back to the to the tupal. So yeah this is as simple as that. Now let's explore a few more tupal methods. Now the length method is used to to get length of a tupil. As you can see we have four to length function. I have provided the tupal which is a. So what length function does it counts how many items are there in a tupole. So in this tupal we have four items. So we have the output four. In this video we will learn about dictionary methods in python. A dictionary provides many built-in methods that allow us to manipulate data efficiently. Using uh dictionary methods, we can add new items, remove existing items, access keys and values separately, update data and perform many other common operations on dictionaries. Now let's dive into the practicals. I have already created this uh dictionary. I will be manipulating and updating this dictionary. I'm going to start with the clear method. Clear method basically removes all the items from a dictionary. So write user the dictionary name where you want to perform this operation dot clear. Now let's print the dictionary name user. So what clear method does? It takes all the items from the dictionary that you specify which is user for me then removes all of them. Okay. Now let's execute the code. As you can see here, we have an empty dictionary, right? This user dictionary, it was emptied by this clear method. It removed all the elements from it. Now, next method that we have is copy. Let's say I want to make a copy of this uh user dictionary. It is also simple. Create a dictionary variable where you want to copy the contents of a dictionary. Let's say user backup equal to now I want to copy this user dictionary. Write the name of the dictionary that you want to copy. User dot copy. The copy method is going to take contents of this specified dictionary and put that into this specified variable. So let's print this user back up variable dictionary variable to be specific. As you can see I have successfully copied contents of this user dictionary into this user backup dictionary variable where I'm printing its content. Now next thing that I want to do is I only want to access the keys right keys like name, ID and salary. I don't want to print their values only the keys. The method for accessing only keys is keys. So write the dictionary name whose uh keys you want to print dot now write keys parenthesis. Now the keys method returns only the keys. Let's execute the code. As you can see it has returned keys, right? Name, ID, salary, right? These are the keys. Now in the next video I will demonstrate in detail how to loop through keys values separately. Okay, for now I just want to to demonstrate methods how they work. Now next thing that I want to do is I only want to access values not the keys. Okay, the method for accessing only values is simply values. Let's execute the code and as you can see it has returned only the values timalu,00 and 100,000. Right? These are the values. Okay. Like I said in the next video I will demonstrate how to loop through loop through keys, values and both. Okay, the next method is something called items. Now item method returns both keys and values. Okay. Uh let's execute the code. As you can see it has returned all the pairs keys and values or the complete pairs. As you can see this is the first pair, the second pair and third pair. Next thing that I want to do is update this dictionary. I want to add more details to this user dictionary. It is simple user dot update we have the update method. Uh in dictionary that we can use for updating dictionaries. Then within parenthesis write the curly braces. Within the curly braces we need to specify the details. For example, let's say address. I want to add address colon let's print the updated dictionary. Now the way update method works is it inserts uh the pair at the end of uh a dictionary. So let's uh execute the code. As you can see the address pair has been appended or added at the end of this dictionary. We can insert multiple pairs as well or as many pairs as you like. Just separate them with a comma like this. Now let's uh in uh add another detail that is going to be designation programmer. Let's execute the code. As you can see guys, both of these pairs have been uh added to this user dictionary, right? And again, the new pairs or details that you add to a dictionary, they are always appended at the end of a dictionary like this. Now let's see how we can merge two dictionaries into one. So we we already have a dictionary called user. Now let's create another dictionary called user 2 coder. Okay. So we have these two dictionary right dictionaries right user and user two. I want to merge them. It is simple. First write the dictionary name where you want to merge another dictionary. So I want to merge user dictionary into user 2. So user dot update within the parenthesis specify the dictionary that you want uh to merge. So the way it is uh going to work, Python is going to take all the key and value pairs from this user to dictionary then merge them with the dictionary that you specify at the beginning. Okay, the contents of this dictionary will be appended or added at the end of this user dictionary. So here I'm uh down here I'm printing the user dictionary, right? So let's uh execute the code. As you can see, we have successfully appended or merged this user to dictionary with user. Right? Now, when you update or merge two dictionaries, the Python doesn't modify or alter the dictionary that you are merging to. For example, user two. I'm merging user two with the user. So, if I print simply the user two, as you can see, its details are intact. So that's how you can update your dictionaries. Another method uh that uh we can use is length len. Let's execute the code. Okay, we have an error. User two is not defined. I think it's user just user. As you can see we have three. So length method it returns the total pairs in a dictionary. In user dictionary I have total three pairs. So we have output three right now. Let's see how we can remove or delete dictionary items. So user dot pop item. Now the pop item method removes the last pair in a dictionary. In this dictionary the last pair is salary. So here uh I'm specifying the dictionary user then dot pop item. So pop item is going to take the last pair from this last pair from the user dictionary and then remove it. Let's execute the code. What? Okay. Okay. I need to remove the length function. As you can see guys, the last pair which is salary is missing because it has been removed by the pop item. Now uh the pop item has one limitation. It only removes the last item or pair in a dictionary. Now I want to remove a specific specific pair. For example, I want to remove maybe ID. So user dot pop within co within quotes specify the key that you want to remove. I want to remove ID. So we need to specify the exact key name. Now the pop method is going to remove this key ID and of course its value as well. So it will get rid of this particular pair. As you can see the ID is missing, right? It has been removed. Let's remove name as well. Now this time it should remove the name as you can see. So that's pretty much it for this video guys. In this video we are going to learn how to loop through a dictionary in Python. Dictionaries store data in key value pairs. Right? And Python provides several useful ways to access this data using loop. So we can loop through just the dictionary using keys method or we can loop through just the values using the values method. And of course we can loop through both using the items method. These built-in dictionary methods make it easy to work with dictionary data efficiently and clearly. Now let's dive into the practicals and see how we can loop through a dictionary efficiently. So write uh for uh and of course I have already created this dictionary that contains these pairs. So I'm going to loop through them. So for i in now specify the dictionary name that you want to loop through. For me it is user user. Now I only want to access the keys. I only want to loop through the keys. So to access only keys we have method called keys, right? So keys, right? Like this print I. Now as we already know the keys method returns only the keys like name, ID and salary. So for loop is going to loop through all the keys one by one. When this loop runs for the first time, the value of this for loops variable will be name. This is the first key, right? So it will print name. And when this loop runs for the second time, then the value of I becomes ID, which is the second key. Then we are printing that here. Let's execute the code. As you can see we have the expected output right. So now again the keys method returns all the keys. So for loop is going to take each key one by one then store uh that key in the for loops variable. Then we are printing that out here. Right? Similarly you can access uh values like demalu 100,000. So as we as we already know the method for accessing uh values is simply values. As you can see we have successfully accessed the values right. So value method returns values. For loop is going to loop through each value one by one. So when this loop runs for the first time the value of i becomes the first value which is dimo. So we are printing this and on the second run value of i becomes uh 1,000. So we are printing that as well. On the third run value of i becomes this. So it is being printed. And when there is nothing more to loop through the loop automatically exits or it gets terminated automatically when there is nothing to loop through. Now I want to access or loop through both at the same time keys as well as their associated values. Now the method for that is items. Right? Now in the for loop we need to define two variables. One variable will store key and the second variable will store value. So key, value. So item method returns both key and value. Now the first variable that you specify in the for loop, it is going to store the key. The second variable is going to store the the value. So key comma value. I'm printing both key and value variables as you can see. Let's execute the code. As you can see name demalu ID 1,00 and sales. So the way it is working the item method returns both keys and values right. So when this loop runs for the first time the for loop takes the first value which is uh key stores that into the key variable then it stores the value in the second variable which is value. So down here we are printing both key and value. It repeats this for all the pairs. when it loops through all the pairs then loop automatically exits. So guys, that's how you can access or loop through keys, values, or both. So that's pretty much it for this video. A set in Python is a built-in data structure used to store multiple unique values in a single variable. It is an unordered collection of unique items. It is it is unordered, mutable, and doesn't allow duplicate items. So let's break down these characteristics. Unordered simply means items have no fixed position. Sets do not use indexing like lists or tupils. A set in Python is mutable which means you can change it after creation by adding or removing elements. However, you can't modify individual elements directly because sets are unordered and don't support indexing. The best thing about sets is that they don't allow duplicates. they automatically remove duplicates. Now let's dive into the practicals and create a set. So a equal to curly brackets or curly braces. A set is created using the curly brackets just like the dictionaries. However, a set doesn't contain key and value pairs. That's the differentiating factor. Let's add a few elements to it. We have successfully created the set called A and it contains these four elements and the set elements must be separated by commas like this. Now let's see how we can access a set. Print a is uh a set as you can see and we have the output as you can see we have successfully accessed the set and all its items. However, you might notice uh something unusual here. This output is a bit uh different, right? The set items are not appearing in the same order as they are created or assigned. This is because sets are an unordered collection. They are not organized in indexes. Therefore, a set doesn't return its elements in the same order as they are created. So they will appear in random order whenever you access them like this. So this is completely normal. So don't get confused here. Now let's say I want to access an individual element. For example, I only want to access 56. Well, we can't do that with sets. Like I like I said, sets are not organized in indexes. Therefore, we can't access them individually. So to access sets individually we have to loop through them for i in a a is a set. So what I'm doing here I'm looping through the set a. So for loop is going to take one element on each run then assign that element to the variable i. Down here we are printing the value of i. Right? As you can see, we have successfully accessed all the items. So when this loop runs for the first time, the for loop takes the first element from this set, then stores that in the variable I. Down here we are printing that variable. Uh then it moves to the next element, it takes this element, stores it in the I variable, then we are printing that variable. So it keeps repeating this process until there is nothing more to loop through. Just like the lists, tupils and dictionaries. Right? So that's how you can access individual set elements. Now one of the best features of a set is that they do not allow duplicates. Right? As you can see for now this list doesn't contain any duplicate items. Let's add a duplicate item 12. Print a. Now the 12 as you can see we have the duplicate of 12 here. Let's print a and as you can see it has automatically removed the duplicate item 12. Right? It automatically removed the duplicate item 12. So a set automatically removes all duplicate items. In this lesson, we will cover the most important set methods in Python and how to use them to add and remove elements and perform operations like union, intersection, ATC. So in short, we will be manipulating a set. So let's dive into the practicals. Let's dive into the practicals. I already have uh this set and we are going to manipulate this set. I'm going to start by adding a new element to this uh set. Let's get rid of this duplicate item. A write the set where you want to add uh the element to dot the method for adding a new element is simply add. Uh let's say I want to add uh 333. Let's print the set. And uh as you can see the the 333 has been added to this set. When you add a new element to a set, it is not inserted at a specific location because uh like I like I mentioned in the previous video, a set is not organized in an indexes, right? So a new element gets inserted in any position. So that's the add method. Now we can also add multiple elements to a set right we can't do uh that with the add method like this it will throw an error as you can see. However we have the update method for that update method allows us to uh add multiple elements to a set. Now update brackets within brackets. You can specify the elements that you want to add. They must be separated by a comma. This time I am inserting these three elements to the set. A let's execute the code. As you can see all the three elements have been added to this set. This way you can add as many elements as you like. Like like this just separate them with commas. Now next uh method that uh we have is clear. Now the clear method clears uh a set. So it will remove all the all these elements from the set and we will have an empty set. As you can see set we have an empty set with no elements. Now let's see how we can remove or delete elements from a set. a dot pop. Now the pop method removes one item from a set and that item can be anything. It removes a random item. Okay, as you can see uh here it has removed 56, right? It is no longer here. Now the obvious limitation of the pop method is that it removes a random item where you can't specify your choice which uh item you want uh exactly to remove. So if you want to remove a specific item then we have the remove method. Sorry remove within parenthesis specify the exact item that you want to remove. Let's say 56. So 56 and as you can see we have removed the 56. Let's remove 550 uh 61. As you can see, we have an error, right? Because this element that I am attempting to remove, this doesn't exist inside this set. So, we have an error. Now, let's remove four. The four is indeed in my set. So, it will remove four, right? As you can see now we have a similar method to to remove which allows us to remove a specific item or item of your choice that is discard. Discard like this write discard. Let's say I want to remove 12 and it will remove the specified element which is 12. As you can see it is no longer in the list. Now let me attempt to remove 1255. As you can see guys, this time we have no error. The difference between discard and remove is that if the element that you want to remove doesn't exist, it will not throw an error. But the remove method if the item doesn't exist, it will throw an error as you can see here. But the discard method doesn't exist, doesn't throw an error. If the element that you are attempting to remove doesn't exist, it simply returns the set. As you can see, now let's move on to the intersection method which is very important. So B equal to let's create another set 45 4 12. So we have these two sets right with four elements each. Now let's apply the intersection method to it. So C equal to intersection B A dot intersection. So a dot intersection then within parenthesis we have specified the second set b. So what intersection basically does it takes the common elements from both the sets that you specify. Here I have specified uh a and b. I'm telling the intersection method that take the common elements from A and B then assign those to the C variable or set variable. So C variable is going to store the common elements in both of these sets. So print C. Let's execute the code. As you can see we have 12 and four. Now these are the common elements in both of these sets right 12. We have 12 here and 12 here as well. We have four in the A and four also in the B. So the intersection method returns the common elements from both the sets that you specify here. Okay. Now let's move on to the union method. So a dot union within parenthesis write b. Now the union method is used to combine all unique elements from two or more sets. In other words, duplicate duplicates are removed automatically. It is one of the most common set operations because it allows you to merge data and also it ensures there are no duplicates in the final results. Okay, so let's execute the code. As you can see guys, it combined these two elements, but it removed duplicates. It did not include the duplicates. In these two sets, we have 12 which is present in both of these sets A and B. It did not include duplicates. We have four which is common. In these two sets, it also did not include the four. It automatically removed the duplicates. So it took unique elements from these two sets then combined them and stored the combined list into the new variable C. So C is storing the unique elements from these sets then we are printing that here. So that's pretty much it for this video guys. There are a few more set methods that we will cover in an upcoming sections. They are not relevant for now. So thank you very much guys. In this video, we are going to take a look at two important functions, split and join. These functions are commonly used when working with lists and strings. We will explore how they work, when to use them, and how they can help us manipulate text data more efficiently. Now, let's dive into the practicals. Let me quickly create a string root admin user. Now I want to take this string and put these three words in a list as separate list elements. So type x. Now specify the string or variable that you want to convert uh into a list dot. Now specify the split. Split method basically converts a string into a list. Now within the parenthesis of split specify a delimiter. Delimiter means how your string is separated. For example in my string as you can see these words are separated by a spaces right. So specify the space. So the way split uh function works is let me first print x. As you can see guys, we have successfully converted this name string into a list. So split function converted this name string into a list stored uh that in the x variable. Then we are printing the variable x. Let's see how it is working. So the way split uh works is it scans your string and checks for the for the specified delimiter which is space. I have specified space right. So here when it scans this string okay it checks root then this root is separated by a space. As you can see here root is separated by space. There is a space between root and admin. So wherever it finds a space it takes that word then puts that in a list item. As you can see it is a separate list item. Then we have admin. Now admin is also separated by a space right as you can see there is a space between admin and user. So it also takes this and puts it as a separate element in a list. So in this list we have three list elements or items. So that's how the delimiter works. Now what if your string is separated by commas like this. Now here as you can see we have a visible difference. Now in this first list we have three separate list items. However in this list there is only one list item because here separator is comma. Right? These three words are separated by comma. However we have specified the delimiter or separator space. So this space doesn't match the commas that are separating these three words. Now if your string is separated by commas then we need to specify the comma as well in the split method like this. As you can see now we have three separate list elements. Right? So that's how you can uh convert a string into a a list. So split method takes the name convert it into a list then stores that list in the x variable. Uh down here we are printing the variable x. This way you can convert any string into a into a list. We just need to specify the separator. How uh items in your string are separated. That that's pretty much it. Now let's dive into the join method. join method is opposite of the of the splitter. It takes a list then convert that list into a string. Okay. So let's create a list. Let's say we have the name names root admin auto. So in this list we have these three uh three list elements right I want to convert this list into a string I want to take these three separate list elements and put inside a string let's say full name equal to first we need to specify the separator how you want to separate these elements so I want to separate them with a comma Uh now sorry not comma space a space right then dot join and provide the list to the join method like this let's execute the code okay looks like uh we have an error name is not defined okay the list name is names here I have specified name let's print full name and uh execute the code. As you can see guys, we have successfully converted a list into a string. So the join method took all the elements stored in the names list which are these then converted them into a single string and then stored the converted value in the full name variable. Down here we are printing the variable. Now here uh we have this space delimiter which simply means how you want to to separate your list elements. We have specified space. So we have space uh between our list elements. What if I specify let's say maybe comma then these elements will be separated by a comma as you can see. So that's the role of delimiter here. We simply need to provide a list to the join method. Then it will convert it into a string. Right? And uh yeah, we also have to tell the join how you want to to separate your list elements. You can specify anything. Maybe space which is the default comma maybe uh this hyphen. This time the string will be separated by hyphen as you can see. So that's it for this video guys. In this video we are going to learn about modules in Python which are extremely important. A module is simply a Python file that contains code. This code can include functions, classes or variables that can be used in other programs. Once you create a module, the code you place or write in that file can be reused across multiple programs. Now there are many functions that are commonly needed in different programs. So instead of writing the same code in every program, you can place those functions inside a module and then import and use them whenever needed. This allows you to avoid repetition, saves time, improves efficiency, and keeps your code clean and well organized. So modules help you organize your code into smaller manageable pieces instead of writing everything in one large file. There are two types of modules in Python. Built-in modules which come pre-installed with Python and custom modules which are created by the programmer. In this particular video, we will focus on built-in modules. A built-in module is a module that comes pre-installed with Python as part of the Python installation, which means they are already built, tested, and ready to use. No additional installation is required. For example, we have the math module. Inside the math module, there are many functions already written to solve different mathematical problems. You don't need to write these functions yourself. You simply need to import the module and use them. Now let's dive into the practicals. Now first thing that we need to do is import the module that we want uh to use. To import we have the keyword called import space. Now we need to specify the module name that you want to import. Uh I'm going to start with uh the math module. So math. So here I am telling Python that import or include this math module inside my program. Once a module is imported or included then we can access all the functions that a module provides. Right? By default Python is designed to be lightweight. Uh it only loads the core modules. It doesn't import the additional modules like math OS and many more. We need to import additional modules that we need manually like this using the import keyword. Now let's see how we can access the functions that this math module offers. Print. Now to access functionality of a of a module write the exact module name which is math for me. dot after dot we can access uh the functions or variables inside a module. Now uh in math module there is a function called square root. So s qrt this is the exact function name parenthesis. Now uh provide it a value let's say 16 square root is going to calculate the the square root of the provided number 16. Let's execute the code. As you can see we have the expected result right square root of 16 is four. So that's how you access function of a module. We write the exact module name then dot after dot we can access the function of a module. Similarly we have a lot of functions in in the math module. So print math uh the next function is uh let's say power. So p o w now it needs two values base and consonant 2 comma 2 ^ of let's say 8. So it will give us uh 256. As you can see this way guys you can access all the functions that the math module has to offer. Okay, syntax is going to remain the same. We just need to know the function uh name that we want to access or use. So, math.p means inside the math module there is a function called P power which which calculates the power of a number. So here calculate calculating 2 raised to the power of 8. Right? So let's go with uh 32bit 2 22 raised 2 raised to the power of 32 and it will give us uh over 4 billion as you can see. And another useful function that the math module offers is math dot factorial uh five factorial of let's calculate factorial of five we have 120 right that's the power of modules right it offers us the problems that are already solved right here in in the math module I'm able to access all these uh functions s without any problems. Right now, without the math module, we would have to solve or write all these functions manually. But here with uh the math module, I just need to access the function name and uh then provide it uh a value or values then yeah it gets it gets us the desired result. That's the power of modules. In the upcoming videos, we will explore a lot of useful modules that you are going to use on a daily basis. So that's pretty much it for this video guys. We are continuing where we left off in the previous video. We are going to explore the random module in Python. The random module is used to generate random numbers and it is incredibly useful for a wide range of tasks. For example, you can use it to generate random numbers within a given range. Create passwords for security purposes. Shuffle items in a list. Select random elements from a list ATC. Now let's dive into the practicals and import the random module. So type import random. Make sure that the spelling is correct. Random. Now first thing that uh we are going to do is generate a random number. So random write the exact module name that is random dot rand int. Now the random module provides a function called rand int. It generates a random number based on the range that you specify uh to it. So we need to provide a range let's say from 1 comma 10. Now rand int is going to generate a random number between 1 to 10. As you can see every time you run the program it returns a random value or it generates a random value between the provided range 1 and 10. 1 and 10 they are also included. Okay let's increase the range from 1 to 100. Now this time it will generate a random number between the provided range 1 to 100. As you can see we have a very similar function uh to rain int print random dot rand range. Uh it also needs a range 1 comma 10. Let's execute the code. As you can see, we have the expected output. However, the rain range is a bit different from the rain int. It does not include the stop or ending value. What is the stop stop or end value? Here it is 10. It doesn't include the end values. So it will generate the random number between 1 to 9. Okay, that's the difference. The rand int includes both starting and ending value. So it can it can generate any random number from 1 to 100. On the other hand, the rand range function is going to generate the random number from 1 to 9. The ending value is not included. That's the only difference. As you can see 9, you will never see 10. Let's increase the range of range range. Now it will generate a random number from 1 to 99. Sorry, like this. And of course guys, you can also store the random values being generated by these functions in a variable as well. Let's say rand equal to this. then we can access the variable. Now this time the rand int is going to generate a random number then store that value in rand variable and down here I can print that rand variable as you can see. Now next function that we are going to explore is called shuffle. the shuffle function that random module provides it shuffles uh a list. So first let's uh create a list a and uh assign it some values. Now random dot shuffle s uf l I hope I'm getting the spelling correct. Now provide a list. Here I I have the list A. So within parenthesis provide a list name which is A. Let's print the list A. As you can notice guys, we have a different list. Right? Now if you notice in the list I have uh specified list elements in this order 12 45 67 8C. But at line number four, uh I have provided the list A to the shuffle function. So shuffle function basically randomizes your list. It takes elements from a list then randomizes them. So every time you run uh your program, it will randomize your list elements as you can see. So that's the shuffle function. Now next function that is extremely useful is choice. Now the choice function selects a a character from a provided string. For example, let's say car characters equal to let's provide it characters including numbers lower case upper case print random choice. Now we we have to provide the choice v choice function either a string like this or a variable that contains a string values. So I'm going to provide it cares variable that is storing this uh string. Now the way the choice uh works is it selects a single character from a given string. So here it will select a single character from this string. That character can be anything. It selects a random character. As you can see four K, right? That's the choice function. It is extremely useful. We will be using it for generating passwords, cryptography, it is. Now, like I was saying, you can also provide it a string instead of uh a variable. So, let me copy this whole thing and put it here. It will produce the same result as you can see. So that's it for this video guys. In this video we will take a look at the datetime module in Python. The daytime module is used to work with both dates and times together. It allows us to perform a variety of useful operations such as getting the current date and time creating or comparing different dates and formatting dates into more readable strings. ATC. This module is essential for handling any tasks that involves tracking, displaying or calculating time and date values in Python programs. Now let's dive into the practicals and import the datetime module. So type import date time. The daytime module is structured differently from most other Python modules. Most modules use standalone functions, but it uses classes to organize its functionality. This class-based design groups date and time operations together. And you don't need to worry about it. We just need an additional step to access its functionalities. Okay. Write x or create any variable name x equal to uh we are going to use the daytime daytime module. So write the exact module name that is date time dot again date time dot now parenthesis. Let's print the x. Let's execute the code. As you can see we have the current date and time. Let me break this down. Now date time. This is the module name. As you can see that we have imported dot datetime. Inside the datetime module there is a class called datetime and dot now this is the method of the datetime class. In classes functions are basically called the methods. Now the now method or function returns the current date and time. It fetches your current date and time from your local system. Then I'm storing uh those details in the x variable. Down here I'm printing the variable x. Right? Let's reexecute the code. As you can see, it returns the date and time. Later in the video, I'll I'll demonstrate how to format this date and time. Obviously, in most cases, we don't need all these details, specifically these microsconds, right? We don't need them at all. Right? Now let's see how we can access individual details such as year, month or week. After now write dot year. Year is basically an attribute. It returns year. This time the x is going to store the current year. And down here I'm printing x. Right? So let's execute the code. As you can see year is 2026. Now let's access the month. month only. Daytime dot daytime dot now parenthesis dot month. Mon month month attribute returns the current month. Month and one we have one. One means the January. We can also access the current hour. So write hour hour return the current hour as you can see 6 hour 6 means it is currently 6 a.m. week. Okay looks like there is no attribute called week. We do have a attribute called an attribute called day. It returns the current day which is 26th of January. We can even access second like this as you can see. And the simple now method returns the current date, date and time like this. Right? Now let's format this date and time. Right? I want only these details like this. I don't want seconds and microsconds. Just these details. Now to customize and display the date and time, we have a method called string format time. Okay, it allows us to customize the date and time accordingly like the way we want it. So what I'm going to do is I'm going to pull the format codes inside my program. Now these are basically called the format codes that allow us to highly customize date and time formatting. They are part of the string format time. Okay, as you can see I have commented them out. So let's see how we can use them. Let me copy this date and time. Now after now dot like I was saying we have string format time that allows us to customize the date and time. So write str f is for formatting. Now write time parenthesis within parenthesis we can use these string formatting codes. All these codes represent a different value. For example, modulus A, it represents the full week day. For example, Thursday or whatever the current day is. So within quotes modulus A, let's execute the code. As you can see, it is Monday. I want to start with year. Here is format code for year is this percentage uppercase Y. It will print the year. Now after here I want to print month for month. The format code is uh this B. So modulus B. Now as you can see January 2026. Okay let's swap these values. January 26. And of course I also need to print the exact day. Format code for printing the exact day is this modulus lowerase t modulus lowerase d as you can see 26th January 2026. And I also want the current time. Okay. So I'm going to start with the hour. Of course modulus H uppercase H for hour. The current hour is 6th and then minutes for minute we have the minute sorry percentage and uppercase m. Let's execute the code. As you can see this is not looking like a time right? If they are looking rather two different values separated by a space. So between them put a colon like this for a proper formatting. As you can see 26th January 2026 the current date and time. And of course we can also you know format these values. You can add hyphens between them like this. As you can see 26th January 2026 current date and date and time. So guys these are the codes that as you can see that you can use. You can use them however you like or whatever order you like. So guys, feel free to experiment with these format codes and let me know if you have any any questions. In the previous videos, we worked with built-in modules, right? These are builtin or pre-built modules that are already part of the Python. Now, we are going to create our own modules. Creating your own Python modules is straightforward. A module is just a Python file that contains functions, classes or variables you want to reuse. Creating your own module is actually quite simple. So let's dive into the practicals and create our own module. Okay. Now, first thing that we need to do is create a Python file. A Python module is nothing just a Python file where we can you know place our code then import that code in our program. Right? So create a new Python file. New. Now we need to save the file in the same directory where you have your main file. Right? My main file where I'm going to import the Python module hello.py. It is in my Python directory. So I will have to store uh my file or module in the same directory as my main file. Okay. So let's save it here. As you can see this is the directory where I have my main file. Here I'm going to save this module. Okay. So let's say pi module dopy. Make sure to add the py extension. It is extremely important because a module is just a python file right that contains the code. Now let's write some code inside this uh file or module x = 90. So here I have uh created a variable. Now I can access this variable inside my module. Okay. Now let's import the module. Write import. Now write the exact module name which is pi mod for me pi m. And uh of course do not include the py extension just the module name. Now the import keyword is going to search for this module in your uh directory where your main file is where you are importing this module in. Now inside this uh pi mode module all I have for now is this x variable. Now I can access this variable. Syntax is simple. Write the module name that you have imported which is pi mode dot x. As you can see x variable is indeed present inside this module. Let's execute the code. As you can see we have successfully accessed the x variable that is inside our module pi mode. Now we have a different value because we changed the value inside this module. Now let's create a few functions inside this module. Let's create a function for adding numbers. Now this function is going to accept two arguments or values a b. Then it will return sum of a + b. Okay. So function name is add. So pi add let's provide it two arguments. Let's execute the code. As you can see we have the 79. So what basically happening here I'm calling this function that is inside this module pi mod. As you can see I am passing these two values 12 and 67. The first value gets stored in the first parameter a. Second value gets stored in the second parameter b. Then here I'm returning sum of a + b. Right? So return function is going to return the sum of a + b. Then here I'm printing the sum of a + b. Right? This way guys you can create as many functions as you like inside a module. Let's create another function called uh multiplication and it is going to accept two arguments as well. It will return a into b. Let's call the function pi mod. This is the module name and the function name is multi Let's provide two values to it and we have the expected result. So guys, this way you can create as many functions, variables or even classes in a Python module. Then you can access those functions or variables inside your main file. We just need to import it like you would import any other module, right? So import then you can access variables or whatever functions you have written inside that module. So that's how guys you can create your own modules. It is very easy. Now creating modules is extremely useful when you are working with big projects where you have you know tens of files right? Uh typically in large programs there are certain functions that you will be reusing a lot. Okay. So in such cases what you can do create a module write those functions that you are going to need repeatedly save them in a module then you can you know reuse those functions like this just import that module then you know use those functions. So let me summarize what we did in this video. To create a module, we just need to create another Python file with py extension and that file must be saved in the same directory where your main Python file is stored or saved. Okay? Because when you import a module, uh your program is going to search for that file in the same directory where uh your main file is stored. That's the only thing that you need to be careful about. We have already learned that Python comes with hundreds of built-in modules such as math, math, OS, and many more. In addition to built-in and user created modules, Python allows us to download and install external modules. These external modules are developed by other programmers and made available to everyone. and they can be installed easily using package managers such as pip. These are known as thirdparty modules or external libraries. They allow us to add powerful features to our programs without writing everything from scratch. Python has thousands of thirdparty modules available for almost every domain including web development, cyber security, data science, automation, machine learning and more. Python's ecosystem is huge and almost any task or domain you can think of already has a module available for it. Now to install, upgrade and manage external modules or libraries, we use a specific tool provided by Python called PIP. PIP is Python's package installer. It allows you to install, upgrade, remove, and manage external libraries and modules that are not included with Python by default. There are two versions of pip. PIP and pip 3. PIP traditionally was used to install packages for Python version 2. It was developed specifically for Python 2. Since Python 2 has reached end of life and is no longer supported and maintained, this version of pip is no longer relevant. Now, pip 3 is used to install packages for Python 3 and later versions. Python 3 is the current version of Python. However, you will still see many people using the pip command to install packages for Python 3. This is because on most modern systems, pip is automatically linked to pip 3 in the background. When you run pip while using Python version 3, it automatically executes pip 3 in the background. As a result, in most cases, both pip and pip 3 install packages for Python 3. Even though pip 3 is is the more explicit and recommended command. Now, let's dive into the practicals. We are going to start by checking the installed modules or libraries external libraries. So type pip. We have the package manager called pip. So type pip or pip 3 space and then type list. It is going to list or display all the installed packages. As you can see these are the packages that I have installed. And this list might be different for you or you may not see anything at all here because I have already installed these uh packages. Right? So yeah, that's how you can check all the installed packages. Now let's see how we can install a package. So open your web browser and visit this website ppi.org. This is the website where all the external uh packages or modules are hosted. This is basically a central repository where you can find all the packages. Now in the search box, type the package that you are looking for. Uh let me search for let's say requests requests. Press enter. And here we have all the matching results. Now I'm going to click on the first match. As you can see guys, here we have the installation command at the top, right? And down here you can find the documentation authors. As you can see, these are the authors of this module. And here that's how you can use this this requests module. As you can see, now let's install uh this requests module here. As you can see, command is given at the top. You can click on it to copy it. Click on it. Once it is copied, back to the terminal or you can also type manually. Now your question obvious question might be which command should I use pip or pip 3 pip 3. So as we have already discussed the if your python version is uh 3 point and beyond then we need to use pip 3. So let's check the Python version. As you can see this is the my current Python version. So if you are installing a module for Python version 3 point and beyond then we need to use pip 3 and pip is exclusively used for Python 2 and Python 2 is obviously no longer maintained. It is old and outdated. Nobody uses the Python 2. However, you can use both pip 3 and pip to install. Okay. So, let's install the requests. So, type pip 3 install. Now, write the package name that you want to install. Make sure that uh you type the correct package name because the package name that you enter must be available in the repository repository of this pip py.org. Right? So press enter. It will install the package. As you can see it has been installed. Now you can install the same package with just simple pip command as well because as we have already discussed if you only use pip then python in the background links to pip 3 because when you use the simple pip command in python 3 version python automatically executes the pip 3 in the background when you only type pip. So it really doesn't matter what you use pip or pip 3. But it is always recommended to use uh pip 3 explicitly when installing packages for the python version 3 like this. You can use of course just pip as well because in many places you will see people using pip. Okay. So in most cases it really doesn't matter whether you use pip or pip 3. So that's how you can install a package in python. So before installing any package, first thing that you should always do is check for that particular module here in the website. Right? If that module is available here, then it can be installed. If it is not here, then you won't be able to install that module with paper. Okay? Now let's see how we can uninstall a package. So first let's list all the packages. I want to uninstall this requests package. So command is simple. pip. You can write pip or simply pip 3 like this. Uninstall. Uninstall. Now specify the exact module that you want to uninstall. Press enter. Okay. un noun command. Okay, sorry I there is a spelling mistake here. Uninstall it is now it should work just fine. Now found requests would remove. Now here as you can see it is it is waiting for my confirmation if I want to uninstall it or not. Press Y. Y is for yes. It will uninstall the uh requested package which is request sir. So guys that's it for this video. That's how you can install and uninstall packages. In this video, we are going to take a look at the time module. The time module is quite simple and focuses manually on delays and timestamps. It is somewhat similar to daytime module, but daytime is more advanced and powerful version designed for working with real dates and times. The time module is mostly used for for pausing your program execution. It has a function called delay which pauses your program's execution. So if you want to delay the execution of a program or create something like a countdown, you need the time module for that. So we are going to start with a simple example, then later we'll create a countdown. Let's dive into the practicals. First we need to import the time module. Now I'm going to write two print statements. Then add a delay between them. So print hello. Let's use the time module. Time dot sleep. Sleep is a function. Inside the time module, sleep function pauses the execution of a program. Now within parenthesis, type let's say three. So time dots sleep. So what basically is going to happen after executing line number three when Python executes this time dots sleep with 3 seconds it will pause your execution for 3 seconds only after 3 second seconds seconds it will execute the next line which is this hello world. So let's execute the code. As you can see, hello. Then we have a delay and after 4 seconds it printed. The next print statement. Let's add the delay of 6 seconds. This time after printing uh this line at line number four, Python is going to sleep for 6 seconds. Sleep for 6 seconds simply means it will pause your program's execution for 6 seconds. only after 6 seconds it will execute the lines of code that you have written after the line number four. Let's execute the code. As you can see hello at line number three then we have a delay here and now we have the hello world. It was executed after the delay of six seconds. That's how we can use the sleep module. So whatever uh number you put in within the parenthesis of sleep, Python is going to pause the execution for those many seconds. Now let's pause the execution for a half second. So 0.5. This time the delay is only of half second. 0.5 as you can see. Now let's create a countdown using the sleep function. So let's create a loop. So I = 10. Loop is going to start from 10. It will keep running as long as the value of I remains greater than equal to 1. Let's print the variable I which is this loops variable. Right? Now let's increment the value of i by 1 and let's implement the time dot sleep and delay is going to be of 1 second. Let's execute the code then I will break down everything as you can see guys. Uh okay this is not what I wanted. Okay. Okay here i minus one. Now we should have a perfect countdown starting from 10 to 1. Okay, we have an error at line number three. I = 10 10 9 8 2 1 and it ends here. So the loop starts from 10 I equal to 10. So it will keep running as long as the value of I remains greater than and equal to 1. So here I'm printing one. So when this loop runs for the first time, the value of I is 10. So here we are checking if the current value of I which is 10 is greater than and equal to 1. Condition is true, right? 10 is greater than 1. So block of loop gets executed. So here I'm printing I. The current value of I is 10. So it prints 10. Now we are decrementing value of I by 1. I uh equal to I minus 1. The current value of I is 1. Sorry 10. So 10 - 1 becomes 9. Now here Python executes this time dot sleep. It pauses your program's execution for 1 second. That's why you know after printing each number there is a delay of 1 second. Now after executing this line control moves back to the y loops uh control structure here. Now the value of i is 9. Right? Now it checks if 9 is greater than equal to one condition is true. 9 is greater than 1. Right? So it prints 9 here. The value of i gets decremented by one again. it becomes 8. 9 - 1 becomes 8. So it adds a delay of 1 second. Right? Now control moves back to the y loop again. Now this loop keeps running until the value of i becomes zero. Now when the value of i becomes zero, python checks if uh 0 is greater than equal to 1. Condition is false. 0 is not neither equal to 1 or neither greater than one. So as soon as condition is evaluated to false the loop exits right here loop is terminated here. So we have this perfect counter. So that's how guys you can use the sleep function of the time module which is extremely useful. In this section we will be working with files also known as file handling in most programming languages including Python. File handling is a core part of most programming languages. It allows us to create, read, write, and delete files. This is incredibly useful because real world programs often need to store data permanently, read from existing files, or manage files by creating or removing them. In Python, file handling lets you create new files, read data from existing files, write or append data to files, delete files when no longer needed. This makes file handling extremely valuable in real world applications. In this uh particular video, we will be reading contents of a file. Now let's dive into the practicals and read contents of a file. To read contents of a file, first we need to open that file. Once that file is opened, then we can read its contents. So type file equal to to open a file in Python. We have the open function. So open within parenthesis we need to specify two things. We have to tell the open function the file name or file path that we want to open and its mode. Okay. First let's uh specify the file name that we want to open. Now I want to open a file here. As you can see in my current working directory which is Python for this session. Here I have this file called demo.txt. I want to open it and read its contents. So let me copy the file name and put it here. Comma. Now we need to specify the file mode within quotes. Specify the file mode. There are multiple file modes such as read, write, append, ATC. Okay. Since I want to read contents of this file, I need to specify the read mode. So type R. R stands for read. In read mode, we can only read contents of a file. Okay. The open function is going to check this specified file demo.txt in my current working directory. Here I have not specified a full path rather only the file name. So when you only specify the file name, the open function will search that file in your current working directory. Then open it if that file exists there. Now my current working directory for this session is this. In my current working directory, I do have this demo.txt file. So it will open this file. So if you want to follow along then create a text file in your current working directory and put some contents in it then specify that file name inside the open function like this. Okay. And later of course I will also demonstrate how to read contents of a file that is located in another directory or location. Now the open function is going to open this file in read mode then store those details in the file variable. As you can see open function doesn't actually read contents of a file. It only opens that file or it establishes a link to that file. Once Python locates the file, it establishes a link to it. Then store those details in the file variable. It is technically called the file object. Let's actually print the file variable and see what it is storing. As you can see in the file variable, we have these details. File name. This is the file name that I want to open. Uh the mode is read and this is the encoding. Right now using this file variable, we can open this demo.txt file. Okay, this file variable is holding the important information that uh that is needed to open a file. Now to actually read the contents of a file, we have the read function. So this file variable as you can see now this is technically called the file object. Using this file object, we can perform operations such as reading contents or writing contents to it. Now let's actually read its content. So specify the variable that is storing your file uh details. For me it is file then dot read uh function actually reads the contents of the specified file. Here I'm telling Python that open this demo.txt file. Once it is opened then we are reading its content. As you can see guys, we have successfully read contents of this demo. TXT file. Right now, by default, the read function reads all the contents of a specified file. As you can see, it has read all the contents. Now, in most cases, we do not directly print contents uh of a file like this. What we have to do is uh store the contents in a variable like this content equal to file dot read. Now the read function is going to read contents then store that content in the content variable and let's print the content variable and re-execute the code. We have the same exact output. Right now the content variable is storing the contents of the demo. TXT file. Now after performing the desired operation on a file, we need to close uh that file. Right here I have performed the operation uh operation which is reading contents of a file. Now after reading its contents I need to close this file which is extremely important and recommended for a better performance. So let's close the file. So file dot close method is going to close the file. Now what does it mean when we close a file? It simply means it will free the resources that this uh file is consuming. Now see what happens is that when you open a file and read its contents your file takes or consumes system resources such as RAM, CPU time, ATC. Now if you open a large file then it takes a lot of system memory or RAM. That's why it is important to close. Once you read uh the contents then we need to close it. Once you close a file then it will free those resources and make them available for other processes. So let's execute the code. As you can see we have no visible uh difference or output at all because nothing happened. The close uh function closes the file in the background. Once a file is closed, you can't, you know, access its contents or perform any operations such as uh writing contents to it. Now let's see how we can read contents of a file that is stored uh in another directory. For example, here I in my desktop I have this dummy uh file, right? I want to read its content. Now the only thing that uh we need to do is specify the full path to this file. We have to tell the open function exactly where this file is stored which is in desktop. So type C c/ Now instead of typing the path manually let's copy the path which is the recommended way. So click on the right click on the file that you want to open. Click on properties here. As you can see this is the complete location or path. Let's copy the path and put it here. Now this is the directory where this uh the file is stored. However, we have not specified the file name yet. So forward slash. Now specify the file name as well. So file name is dummy uh dummy sorry dummy. Now after the file name we need to specify the extension as well which is extremely important. Now to find the exact extension again go to the property and uh the extension is txt. So dummy.xt. So here I'm telling open function that go in my desktop and inside desktop I have this dummy.txt file. Open it in read mode. Now it will open this file and down here we are printing its contents. Let's see if it works or not. And we should have our first error. As you can see we have the syntax error. The exact error is this uni code escape. Now what uh basically is happening here? Now the error is this backslash. What basically is happening? If you remember guys, we use backslash to start a special character or an escape sequence uh like back slashn which creates a new line or back slash t etc. right so here I have provided this backslash. So when you write a backslash uh inside a string like this, Python assumes that you want to write an escape sequence. So after backslash, it expects you to write uh something like n or t. So it is not interpreting it as a path separator. Rather, Python is assuming that you want to start an escape sequencer. That's why we have this error. So to fix this error, it is simple. Just write R at the beginning or before the double quote like this. R stands for raw. Raw means interpret this backslash as it is. Do not interpret it as as a start of an escape sequence. Okay. Now it should fix the error. As you can see I I am a I am reading contents of this dummy. txt file which is located at uh this path. Okay. So if you do not want Python to uh interpret backslash as a start of an escape sequence then write r it will interpret or read it as as it is not a start of an escape sequencer. Now there are multiple ways to fix the same error. Just remove the R. You can write two backslashes like this. It will fix uh the error as well. Let's execute the script as you can see. Or you can use uh forward slash. It will also fix the error. Let's execute the code. As you can see now the recommended way uh to remove this error is this R. Okay, just specify the R. Then you can uh you can you know specify either backslash or forward slash. It doesn't really matter as you can see. So this is the recommended uh method. Use R and then you can use back slash or forward slashes like this. So that's pretty much it for this video guys. We will continue from where we left off in the previous video. In this video, we will learn how to read a specific number of characters from a file as well as how to read multiple lines or any number of lines you want. Now let's dive into the practicals here. As you can see, I already have the open function and I am opening a demo.xt file in the read mode, right? and then storing those details in my file object or file variable. Right now let's print uh the contents of the demo.txt file. So file dot read function is going to read uh the contents of demo.txt file and print function is going to print that content. Right? Let's execute the code and we have the expected output. Right. The way uh the read function works is by default it reads all the contents of a file. This is exactly what is happening here. So read function has read all the contents of this specified file. Now let's say you want to read a certain number of characters then we have to provide that number uh within the read functions parenthesis. So five this time the read function is only going to read the five characters from the beginning. Okay, as you can see it has read the exactly five characters. Let's make this number 15. This time it will read 15 characters. So whatever number you put in here, the read function is going to read that many characters from the beginning. Let's go for let's say 77. This time it should print 77 characters. As you can see now we are going to read contents of this file line by line one line at a time. Uh now the function for reading an entire line is read line. The way the read line function works is it reads one line at a time. So let's execute the code. As you can see guys, it has read the first line. It obviously starts from the first line. So read line is going to read the first line from this specified file. It reads the entire line. Now what happens if you execute the same read line function again? This time as you can see we have two lines. Okay. So when I executed the read line function for the first time, it read the first line and when I executed it for the second time, then it automatically moved to the next line and read that line as well. Now if I execute read uh two more times, then we should have four lines. So as you execute the read line function, it automatically moves to the next line. Right? Now let's say I want to read maybe first 100 lines. Now if we keep going with this method then we we need to write 100 read line functions obviously which is not efficient and scalable. What we can do is obviously use the for loop. Okay. So for i in range uh let's say I want to actually uh read seven line because in this file I don't have 100 lines. I only have like 10 or 12 lines. So let's go for uh seven. Now this for loop is going to run seven times. Okay. Because loop is going to start from 0 to 6. And in the block of this for loop, write the read line function. Okay. Okay. We have an error at line number three for i in uh range. Okay. I forgot uh the obvious colon. Now it should fix the error. Let's execute the code. As you can see guys, it has read the exact seven lines. Okay. 1 2 3 4 5 6. Okay. We also have an empty line. empty lines also get counted. Okay. So the way it is working is when this loop ran for the first time the read function was executed. So it read the first line and uh using printing print function we are printing it. When this loop ran for the second time the same read line function was executed. So it read the second line. On the third run this read line function was executed third time. So it read the third line. So read line function keeps reading the lines as long as this loop keeps running. So this loop runs seven times. So it reads seven lines and uh after that this loop gets terminated. So after that it will not read any more lines. Okay. So guys that's how you can utilize this read line function efficiently. And of course I almost forgot close the file. So when uh the Python exits this for loop here I am using the close function which is going to close this file and make uh the resources consumed by this file available to other processes. As you can see in this video we are going to take a look at the with statement in Python. As we have seen, it is important to close files after performing operations such as opening or reading their contents or writing contents to it. This is an important part of a proper resource management. However, manually calling close can lead to problems if you forget to close the file or an exception occurs before close is executed among others. This is exactly what the with statement solves efficiently. The with statement in Python simplifies resource management by automatically handling system resources. It is commonly used with files, network connections and databases to ensure resources are properly released even if errors occur or you forgot to close. That makes your code cleaner and more readable. Now let's dive into the practicals. So write with and let me comment uh this line out and uh let me copy the open function with parameters as file. Now guys this line is equal to this exact same line right these two lines are doing the same thing. So here I am opening this uh demo.txt txt file in the read mode then storing the those details in the file object or file variable. Now I'm doing the same thing here with the context manager with it is going to open this demo.txt file then as keyword it is going to store those details in the file variable. Now colon within the block of uh this uh with statement we can read the contents of the file. So file as you can see here file dot uh read let's execute the code as you can see we have the expected output we have successfully read the contents of this file okay so yeah this is the with uh statement okay it handles the system resources efficiently now with the context manager with we do not need to close the file manually the way we have been doing so far Right? Like this pi file dot close. Right? It is not required because by default the width statement is automatically going to close the file. So how it is basically going to uh going to work is here at line number four we are reading the contents of the file. After this we do not have any lines of uh code. So after the last line, it automatically closes the file automatically in the background. Now with the context manager, it looks much more cleaner, right? The code is much more organized. We have to write everything within the block of the with statement and it also automatically closes the file after the last line within the block of width. Now the close function is not required. Okay, you don't need to write it uh manually with the with statement. It does automatically this for us. Okay, so guys, that's how this with statement or context manager works. In the previous video, we read the content from if file line by line using the read line function, right? The obvious shortcoming of the read line function is that we can't directly access a specific line, nor can we easily read all contents at once or read a specific range of lines. The read lines function addresses these issues effectively. The read lines function can read the entire file content and store each line as a separate element inside a list. Once the lines are in a list, we can easily loop through that list to process each line one by one. The method is useful when we want to quickly load all lines and then work with them through a loop instead of calling read line repeatedly. Now let's dive into the practicals. Here I have already opened this demo.txt file in uh the read mode. Right? So uh let's first read uh the contents of this file using the read uh method. Let's execute the code. As you can see the way the read function works is it reads all the contents of a file as a single joint string. Now we have uh another function called the read lines. Now read lines function is similar to read function but it returns the content as a list where each line is stored as a separate list element. So let's execute the code. As you can see here read lines function has returned the content of this file as a list. As you can see at the beginning we have the square bracket. Square brackets are obviously used to define a list. Right? In this list, as you can see, we have contents of this demo. .txt file. The way it works is each line is stored as a separate list element. As this is the first line as you can see this is the first line here. This is the this first line is stored as a separate list element or list item. Now this is the second line and we have comma after comma we have the second line. Now before we proceed further as you can see we have something unusual at the end of each line we have this uh back slashn which is the escape sequence for a new line. As you can see after each line you will see this back slashn or new line character. Here we need to understand how files store text lines. Files use new line characters uh which is back slashn to mark the end of each line. When you are using a text editor and press enter, your text editor does two things. It moves your cursor to the beginning of the next line and internally it also inserts a back slashn or new line character at the end of the current line automatically. Now when a text editor or a program reads file content the back slash n character is treated or interpreted differently than standard characters. It is not displayed or printed as the literal character back slashn. Rather, it is interpreted and executed as a control instruction. Okay. When a text editor or program encounters back slashn, it immediately moves the cursor to the beginning of the next line. Now the Python's read line function is designed to read contents of a file exactly as it is stored on the disk. This includes the hidden escape sequence like back slash n. Now since the read line function returns contents of a file as a list. Now we can access uh the individual list items using indexes. Uh so first let's store uh the contents that read lines function reads in a variable. Let's say lines. Uh let's print uh lines. So here I'm reading contents of the demo.xt file using read lines function. Then storing that in the lines variable. Right now lines is a list. As you can see this is a list right? Read lines as we already know the read line lines function reads contents then returns it as a list then we are storing that in the lines variable. Now let's say I want to access only the first line then type zero the first element. This is the first element of this array uh sorry this list. So we should print the first line as you can see. Let's print uh line number two. As you can see, we have successfully printed the first two lines. Now, let's loop through uh through this lines list. So, for i in lines. So, I'm basically looping through this lines list. I want to print all the lines one by one. So print I. As you can see guys, we have looped through all the lines that are stored in this file. Right now we also have these unnecessary empty lines. I will get back to this in a minute. So first let me walk you through what is happening here. So using read lines function we are reading contents of this file. It returns the contents as a list and we are storing that in the lines variable. Then we are looping through this lines list one by one. Now here we have an obvious problem right? We have all these unnecessary empty lines. If I check the contents of uh uh this file that I have opened using read lines which is demo txt. As you can see uh in inside uh this this file I do not have any unnecessary empty lines right let's analyze how this read line lines function reads the contents as you can see read line function reads contents like this right it returns a list and at the end of each list item we have this back slashn right back slashn is a new line character error. So when this print function reads this entire line, it prints this line and it also executes this escape sequence which creates a new line. Now by default the print function automatically adds this escape sequence back slashn at the end of each line. Now here the print function executes the back slashn two times. Okay, the first back slashn gets executed because it is part of this line. Right at the end we have back slashn and the second back slashn is automatically added by the print function. That's why we have an additional empty line. Now to get rid of this we simply need to use end parameter of the print function. In print function we have a parameter called end. So end equal to nothing or empty. So what basically end does it overrides or prevents the default behavior of the print function. The default behavior of the print function is that at the end of each line, it inserts the hyphen n to create a new line. So when you specify the end parameter equal to nothing, it will not add this back slash n escape sequence at the end of each line. So it will not create an empty line. So let's execute the code and it should fix the problem. As you can see, it has fixed the problem. Now we still have uh you know contents being printed line by line. This is because that new line is created by the backslash n that we are reading from uh these array elements. So when Python reads this line, it prints this line and then we have escape sequence then this escape sequence backslash and it creates a new line. Right? Now let's uh print a specific number of lines. Let's say I want to print first three lines. Then it is simple. Here we can provide a range from zero. Zero is the first element from three. So it will print first three lines. Let's execute the code. As you can see guys, this time we are slicing this array. I think we did the slice array slicing in the arrays section. Right? So zero means the index is going to start from one. Then we are providing three. Now the number that you provide does not get included. Rather whatever number you provide here that number gets subtracted by one. So range is starting from zero and ends at 3 minus 1 which is two. So 0 is the first index. Second index is 1. Third index is two. Right? This way you can print lines in any range. Maybe let's say from 3 to 6. As you can see, we have we have printed lines from 3 to six. Now let's close the file. file dot close. Now it is always recommended to close a file once you have performed the desired operation. In this section, we will explore error handling in Python using try, accept and finally blocks. Handling errors properly is one of the most essential skills in any programming language. Before we dive into practical error handling, we need to understand the type of errors in Python. This will set the context for learning how error handling works. There are two main types of errors. Syntax errors and runtime errors. Syntax errors occur when there is a mistake in the structure or syntax of the code such as missing quotation mark or missing colon maybe missing closing parenthesis ATC. Now these errors are detected by Python during parsing before the code is executed. Now the code parsing in programming means the process where a language interprets, reads and analyzes your code line by line to understand its structure and syntax before execution. Before your code is executed, Python parses it to make sure that your code is written correctly. During parsing phase, Python detects syntax errors along with other structural issues. Once Python successfully parses the code without any syntax errors, it begins executing the program. During this execution phase, certain errors may emerge that could be detected only when the code is actually running. These are known as the runtime errors or exceptions. For example, if you try to divide a number by 0 using an expression like 23 divided by 0, it won't cause a syntax error during parsing phase because there is nothing wrong syntactically. However, when Python tries to execute it or divide it by zero, it throws or raises a runtime error because division by zero is not allowed. Another example is working with files. If you provide a file path that doesn't exist, Python will raise an error when it tries to access the file during execution. Such runtime errors can be a big problem because when Python detects a runtime error, it immediately stops code execution. Your program crashes or stops right there. To catch and handle runtime errors, Python provides a feature called error handling. Error handling is used to deal with runtime errors using try and accept blocks. These blocks allow your program to catch and handle errors gracefully so it can continue running without crashing or stopping. Using try and block we can easily catch runtime errors and allow the code to continue running without halting. Okay, I'll demonstrate it practically in the next video. We are going to continue from where we left off in the previous video. In this video, I will demonstrate how to catch and handle runtime errors efficiently with practicals. Now, let's dive into the practicals. Before explaining the try and accept blocks, I'm going to I'm going to demonstrate how Python handles the runtime errors. This will set a good context for learning the try and accept blocks or exception handling. So what I'm going to do is I'll try to divide a number by 0. 12 divided by 0. Now the way Python execution works is before actually executing the code, Python does something called the code parsing. In the parsing phase, Python checks for the syntax errors. syntax errors like uh maybe you have closing parenthesis missing like this. Let's execute the code. As you can see, this is called the syntax error. The opening parenthesis was never closed or maybe maybe you have an unnecessary code in your code, it is also a syntax error as you can see. So this is what Python does in the parsing phase. It detects these syntax errors. However, if you check uh this piece of code 12 divided by 0, it will not generate any syntax error because when Python parses this uh this code, it sees that okay, here I'm trying to divide these two numbers, right? So, it will pass the parsing phase. Here I'm simply trying to divide uh two numbers. Python doesn't detect these runtime or logical errors in the parsing phase. However, when Python actually executes this code there, it will generate an error when Python will try to divide 12 by 0 which is not possible. So, it will throw an error. That error is called the runtime error because uh the error is caught uh during execution or runtime. The major drawback of uh of runtime errors is that uh it crashes and terminates your program. For example, let me write a print statement. Hello. As you can see, the line error was caught at line number one. So, as soon as this runtime error was uh detected, the program stopped right there. It crashed right there. all the lines of codes written after it will not be executed. Now to handle the runtime errors efficiently, we have something called exception handling or try and accept blocks where we can uh we can catch these errors and continue the uh rest of the codes execution. So write the try keyword try colon press enter. In the try block, we need to write the code that we want to implement. Let's say 12 divided by 0. Now in the accept block, outside of the try block, write except colon. Make sure that there is indentation in both try and accept blocks like this. Print. Let's catch the error. Can't divide by zero. So the way try and accept uh blocks work, they work together. In the try block, we write the code that we want to implement. And if Python catches any runtime error in the code that you write in the try block, then that runtime error is passed to the accept block. In the accept block, we handle that error. So let's execute the code. As you can see, can't divide by zero. So in the try block we tried to perform 12 divided by 0 which generated a runtime error that error was passed to the accept block. In the accept block we are handling that error. So that's how try and accept blocks work. In the try block, we write some code and if the code that you write uh within the try block generates a runtime error, that error is passed to the accept block where we handle that error and it will avoid the program crashing. For example, the execution continues. Let's execute the code. As you can see, we successfully caught the runtime error here in the accept block. Then we have this print statement outside of these two blocks. So, Python executed this print statement. So, it did not uh crash or terminated the program after handling the error. Rest of the execution was not disrupted. Everything was executed as it should be. So that's that's why the exception handling is extremely important. Now to simplify catching runtime error handling, we can use the built-in exception types that Python provides. In the exception definition, we can specify the type of error we want to catch. This allows for targeted error handling. For example, division by zero. As you can see division by zero it generates this particular error zero division error. Now we can catch this specific error by specifying this error in the accept block. Okay. So copy this uh error as it is now except space paste it here as e. So this time I'm telling Python that catch this specific error only zero division error right. So if in the try block Python catches a zero division error then this accept block will catch that particular error zero division error and the error message will be stored in the E variable. As you can see as E in the E variable the error message will be stored. So this time we are handling it automatically. Let's execute the code. As you can see, division by zero. So here in the try block, Python detected the division by zero error. And in the accept block, we are specifically catching uh the division by zero error by specifying the built-in zero division error. So it catches that error. The generated error message is stored in the E variable. Then down here we are printing that variable, right? The variable as you can see it is storing this particular error division by zero. Similarly just like zero division error error exception handling provides different options and exception types for catching various kinds of runtime errors. We will explore them as we progress in this course. Now we can also use ex else with try and accept. So else print no error was detected. No runtime error was detected. Let's execute the code. Now as you can see the else block is only executed when uh the try block does not detect or catch any runtime error. So let's divide 12 by 2. As you can see this time we have six because it is a valid expression right 12 divided by two is six. So no runtime error was detected. So when uh the try block doesn't catch any runtime error the else block gets executed. But if I divide 12 by 0 then the accept block gets executed. Here we are printing the error message and catching the error. The else block was not executed. So it is only executed when Python doesn't catch any errors in the try block. So that's it for this video guys. In this video, we will take a look at the finally block which is also part of try and accept. The finally block is an optional part of the try except structure in Python. The finally is a special block that always runs no matter what happens in the try or accept blocks. Now let's dive into the practicals. So uh let me write try block print except can't divide by zero sorry zero right so if I execute the code we are catching uh the division by zero errors error right so in the try block we write the code if it raises a runtime error then the accept block gets executed that's how it works if there is no runtime error in the try block then yeah except block is not executed we also have finally so write finally outside of blocks of try and accept like this print code continues. Now the way finally works is it will be executed whether there is a runtime error or not. Okay, for example, as you can see here in the try block, Python did not catch any runtime error, right? 12 divided by 2. So we have the result and the finally block was executed code continues. However, if I try to divide by it by zero as you can see can't divide by zero this time since Python raised or detected a runtime error. The accept block was executed but finally block was also executed. Okay. So finally block is executed whether Python detects a runtime error or not. The finally block is always executed. The else as we learned in the previous video the else block gets executed when there is no runtime error. Right? So here as you can see here Python did raise a runtime error. So block of else was not executed. But if I divide 12 by two, it will not raise a runtime error. As you can see the block of else was executed. So else when it is used with try and accept, it is executed only when Python doesn't detect any runtime error. However, finally block is always executed whether Python detects or doesn't detect the runtime error. So that's the finally block. It is optional. As you can see the binary block is executed even though Python did not raise any runtime error. And if Python does raise a runtime error, it will still be executed. So that's how the finally block works. So that's it for this video. In this quick video, I'll demonstrate the use of exception handling with real world examples. This way you will uh get an idea of how important the exception handling is. So what I'm going to do is uh I'll ask user to enter two numbers. Okay. Then try to divide them. So a equal to intput enter first number second number. So let's say you are creating a calculator app right where you are allowing users to to enter numbers. And uh of course we don't know what users can enter. So here let me try to divide a divided by b. Sorry let me replace a with b. So this small calculator application let me execute it. As you can see it is allowing user to enter two numbers. Okay. And uh the program is going to perform division. Okay. Let's say user enters 56 then second number is zero. As you can see division by zero because we can't trust users right what what they will enter we have to prepare our program for every possibility right they can enter anything like like zeros so if your program doesn't handle these errors then yeah your code does look very unprofessional and ugly. So it is important to handle these runtime errors. And of course we can uh handle these errors with try and accept block except let me copy this specific error that I'm going to catch as E. Print E. Now let's execute the code. As you can see now we are handling this error gracefully. So that's the use of the exception handling. We can't trust the user inputs. We we have to prepare for every possibility, right? So our program can work smoothly. So that's it for this video. In this video we will learn how to create files, write contents to them and much more. This is going to be an important video. Now let's dive into the practicals and uh write contents to a file. File equal to open. Uh let's specify a file name. Let's say dummy12.txt, W. This time the file mode is W. W stands for write. It allows us to write contents to a file. As you can see in my current working directory, I don't have term12. TXT file. So the way uh the right mode works is the file name that you specify here if it doesn't exist then it will create that file. Okay. So let's execute the code. Uh first let me save the code. As you can see this file doesn't ex is not here in my current working directory. ls as you can see the dum12.txt has been created. Now let's write contents to it. File dot write. Now we have the write method. The write method is used to write contents uh to a file. Now we have to tell the write function the file name where you want to write the content to. So here I am providing file dot write. So write function is going to write contents to the file dum12. txt right because this file object or file variable is storing these details including the file name where the content will be added. So within quotes let's write content let's say a new line added let's execute the code and we don't have any output or errors we don't have output obviously because we are not printing anything let's ls now let's open contents of this file in notepad as you can see guys a new line added this is exactly what we added to this dum12.txt file. Right? So that's how you can uh you can add content or a line to a file using the write function. Now we need to close the file which is very very important. Now closing especially when writing contents to a file is important because if you keep the file open then processes within your program might add data to your file which which will cause the problems and obviously it will consume your system resources as well. So it is important to close the file. Now the write function allows us to add only one line at a time. Now if you want to add multiple lines then we have to use write lines function like this. Now we need to specify the lines within a list. Okay. So within write functions parenthesis write uh square brackets which are used to define a list. Now specify the lines that you want to uh append line number one. Now we need to specify the new line character or escape sequence. If you don't then all the lines will be written uh as a single string or in a single line comma line to comma line number three. This way you can uh include as many lines as you like. Line number four, escape sequence or new line character. Make sure that the lines or list items are separated by a comma. This is mandatory. Let's execute the code. So this time the write line lines function is going to add these four lines to this dum12.txt txt file. Okay. Okay. We have an error. Unexpected character line continuation character at line number three. 1 2 3. We have comma placed properly here. Okay. Okay guys, I see I see where the error is here. I have closed this string inappropriately. So remove this and string must be closed here after the back uh backslash and new character. Now I think this should fix the error. Okay, we don't have any errors. Uh let's uh open uh the file. As you can see guys, this time we have successfully added these four lines to this file. This way you can add as many lines as you like to a file like this. Okay. Now important thing that you should understand is this new line character. If you don't specify the new line character or back slashn at the end of each line, then all these lines will be stacked like this. So back slashn basically creates a new line. That's why we have lines separately in new lines. Right? Now as we discussed in the previous video, it is recommended to use the context manager width. So here what I'm going to do is uh write with open as file and put these lines within the block of width. So here I'm using the context manager opening this file as file. Now we have the file variable or file object and here I am writing these lines to this dumb one dot txt file down here and now down here I don't need the file dot close function because the context manager with is automatically going to close the file after the last line because after line number five I don't have any more lines so it will automatically close the file. Let's execute the code. As you can see, we don't have any errors. It means the code is working perfectly, right? And before signing off, you can create a file at any location. Right? If you don't specify a path here, then by default, the open function is going to create file in your current working directory. But if you want to create a file at a specific location, then you can uh specify path to that directory. Let me actually show it to you. Let's say I want to create uh create a file in my desktop. So what you are going to do? Go to the directory where you want to create the file. I'm in my desktop. So right click in empty space. Click on open in terminal. I just want to grab the current working directory. pwd. This is the complete path. and let's copy it and put it here back slash let's create a file called d123txt and of course we have to add r at the beginning to to interpret the path separator backslash as it is not as a start of an escape sequence this time this d 1 2 3 5 1 to do txt file will be created in a desktop. Let's execute the code. As you can see, we don't have any error. Let's go to my desktop. And here we have the file D12. Right? Let's uh open the file. In this file, we have the we have these four lines. These are the exact lines that I have written to this file here. Right? In this video, we are going to explore the OS module in Python. It is one of the most important modules that every programmer should know about. The OS module uh is your go-to toolkit for interacting with operating system. It allows us to manage files, folders, and process information regardless of whether you are on Windows, Mac OS, or Linux. It is a built-in library that provides a way to interact with the operating system. It allows us to perform tasks such as creating and deleting directories, reading and writing files, checking whether files exist, and getting information about the current working directory and much more. Now, let's dive into the practicals. First, we need to import the OS module, right? So, import OS. We are going to start by checking the current working directory. the type print os dot get cw. Now the get CWD function of the OSI module, it returns your current working directory where you are currently in your file system. So let's execute the code. As you can see guys, we have this output. This is my current working directory. Right now let me change my current working directory to something else. Let's say C drive. Now uh let's execute the code. As you can see, it has returned my current working directory which is now C drive. Right? Let me change my current working directory back to my previous working directory which is Python. So yeah, this is as simple as that. It returns your current working directory. Now I want to to check the contents of uh of a directory. So os dot list diir. Now list diir uh displays the contents of your current working directory by default. As you can see here I have not provided it any specific directory. So if you don't provide any directory path then it will list contents of your current working directory. Let's uh execute the code. As you can see this is the contents of my current working directory which is this Python right now it returns contents in a list. As you can see as you can see we have the opening and closing uh square bracket right it represents a list. So all the files and directories are put inside a list and each file and directory is a separate list item. So as you can see this is what I have in my current working directory. Now if you want to access these items individually then we can loop through this list that the list diir returns. Okay we can also do something like this. As you can see it means I am accessing the first item from the list that it returns. Right? Similarly, I can go for let's say three. It will display the third item or list item which is files. Now let's loop through this entire list for i in and print i. Now we have uh looped through each file and directory in my current working directory. So the way it is working uh the list diir function it returns a list that list contains all the files and uh directories. Right? Then we are using the for loop. For loop is going to loop through each item one by one. Now uh let's uh list contents of a specific directory or drive. OS list diir within quotes. Specify the drive name or the path to your directory. Uh let's say C. As you can see guys, this is what I have in my C drive. It has listed all the contents or files and directories inside the C drive in a list as you can see. And of course you can loop through uh all the items using a loop as we did just a minute ago. Right now let I want to check the contents of uh a specific directory. Let's say the desktop. So what I'm going to do is go to my desktop. Right click in the bank blank space. Click on open in terminal. Type uh pwd. Uh it stands for present working directory. Let's copy the path uh to my desktop directory and then let's put it here within quotes. Let's execute the code. Okay, we have the expected error syntax error. Uni code error can't decode bytes. Now the error is obvious right here. The list di function is is not interpreting this backslash as a path separator. It is interpreting it as a escape sequence or start of an escape sequence. We have already talked about it in the in the file management section. Right? So to get rid of this error just write r before the before the quote. It will fix the error. Now as you can see this is the contents of of my desktop directory that I have specified here. So that's the list diir function. Now let's move on to the next useful function that OS module provides which is change directory. So chdir chdir stands for change directory. It allows us to navigate in our file system. I want to change my directory from my current working directory to something else. Okay. I want to change my directory to to desktop. Okay. So within quotes put your directory path where you want to switch to or change to and let's execute the code. So here I'm telling my change DR function that change my directory from my current working directory to this specified uh path or uh directory which is uh the desktop. Let's execute the code. As you can see it doesn't actually returns any output or string. It internally changes your your path to the specified uh directory which is desktop. Now let's uh check uh the current working directory using the get cwd method. Let's execute the code. As you can see guys, my current working directory is now desktop because at line number three, I'm telling Python that uh change my directory to desktop. Then here at line number four, I'm printing my current working directory which has been changed to the desktop. So this is as simple as that. Next let's see how we can create a directory. So print os dot make diir. Make diir creates a new directory. Now within parenthesis of make diir write the directory name that you want to create. Let me ls here. Now let's create a directory called uh demo12. So make d uh is going to create this specified directory name demo12 in my current working directory which is python. Let's execute the script. It has returned none. This is true because it doesn't return any string or output. It internally creates the directory name that you specify here. Let's ls. As you can see, demo12 directory has been created. Now I want to create a tree of directory means a directory inside directory. Now function for uh that is make make dirs timalu forward slash root. So this make d function creates a directory inside directory. So it will get directory demalu and subd directory root inside it. So let's execute the code. none ls as you can see dimallu directory has been created. Let's check its contents. ls uh dimallu as you can see inside demalu we have the subdirectory root. This way you can create as many subdirectories as you like. Like like this root 1 2 3. Now this time it will create a tree of all these directories. Dimalu inside demalu it will create root inside root 1 2 3. Then inside 1 2 3 directory it will create 54. Let's execute the script. ls dimallu. As you can see inside imal we have uh root and uh inside root we have 1 2 3 and inside 1 2 3 we have 454. Now let's see how we can uh remove files and uh directories with OS module. So print os dot rm diir r r r r r r r r r r r r r r r r r r r r rmd diir is short for remove directory as its name suggests it allows us to remove a directory. Okay, let me create an empty directory make root ls. As you can see the the root directory has been created. It is an empty directory. So let's remove this. Now within quotes specify the exact directory name that you want to remove ls as you can see root directory has been removed. Now rmd function is going to remove the directory root in in the current working directory by default. Root directory as as you can see is no longer here. Now the limitation of the rmd function is that it only removes empty directory. If a directory has subdirectories or files inside it, then it will not be able to remove that particular directory. For example, ls here. Let me check contents of the files directory. Inside the files directory, I have this content, right? So let me attempt to remove files directory using the rmd function. So let's provide the name files ls. As you can see the directory is not empty right? It has some contents in it. So that's the limitation of the rmd directory. Now how to remove directories with contents that will be discussed in the next video. Right now, let's remove a file. I'm going to remove this demo .txt file. Let's copy it and put it here. As you can see, direct the directory name is invalid. Obviously, the function name says rmd. It only removes directories. To remove a file, we have the remove function. ls. Now I want to remove this uh demo dot txt file within parenthesis of uh remove put the direct file name that you want to remove and it will remove this demo. txt in my current working directory. ls uh sorry I need to execute the code ls now the file has been removed right that's how you remove a file and uh this remove function only works with files it only removes files not directories now you can remove uh a file at any location just specify the path to that particular file wherever it is stored okay Now the next thing that we are going to check if a file or directory exists or not. So print os dot path dot exists exists. Now within parenthesis you have to specify the file name that you want to check. Let's say hello. py. Now this exists method checks if the specified file hello. py exists or not. By default it checks in in my current working directory. And obviously in my current working directory this hello.py file does exist. So let's uh try to execute the code. As you can see it has returned true. So it returns true only if the file or file path that you provided exists. Since the hello.py does exist. So it has returned true. Now let's provide an invalid file name. As you can see false. It means the file is not present in my current working directory. Now let me specify path to a file that is stored in another location which is desktop. So, right click properties. Let's check uh copy its path and put it here. Okay. In desktop, I have this file called HDM. HDM txt. It is very important to specify the extension as well. And uh here at the beginning write r so that uh python doesn't interpret uh the backslashes as the start of an escape sequence. So let's execute the code. As you can see true means this file does exist in my desktop or uh this given at this given location. Now the exists method also checks for uh for a directory ls. Okay, let me resize the terminal ls. Now here as you can see I have this files directory. So let's provide the files directory name. As you can see true means the files directory exists. So it checks for both files and directories. Uh now what I'm going to do is remove the file name and uh see what it returns and we have true because this desktop as you can see this is a directory since this directory does exist so it has returned true. That's how we use the exists method. Now another important function that OS module provides is name. Now the name returns name of your operating system. Okay, here we don't need to put the parenthesis like this. Just OS.NAME. Uh let's execute the code. As you can see means this is a Windows operating system. Now let's see how we can execute commands uh inside your Python scriptor. So we have os dots system function. It allows us to execute commands within parenthesis. Write the command that you want to execute. Let's say diir. Let's execute the code as you okay. Did you mean system? Okay. Uh spelling mistake here system dir command uh displays contents of a directory. Right? So let's execute the d command first. As you can see this is the contents of my current working directory. Now I'm executing the same command inside my python program. So it will produce the same output. So let's execute the program. As you can see, it has listed contents of my current working directory. This way you can execute any command in your uh inside your Python script. Just write the command name within the quotes. Now to execute a PowerShell command, we have to write the PowerShell before the actual command like this. PowerShell then uh let's execute get process command. Get process command in PowerShell displays all the running processes on a system. Now if you want to learn more about uh PowerShell then I have included the PowerShell in my cyber security course that that you can you know check out if if you if you want to dive deeper into the PowerShell. Now it is going to display all the running processes in my system. As you can see guys, this is the get process command. Similarly, you can execute any PowerShell command. Let's say get service and it lists all the services. Okay, spelling mistake guys. Service. Now it will list all the services like this. So that's it for this video guys. Thank you very much for watching. Let me know if you have any questions. In this video we are going to take a look at the shuttle module. It stands for shell utilities. It provides highle operations for working with files and directories such as copying, moving, and deleting them. Similar to the OS module. However, as we saw in the previous video, the OS module has one limitation that it doesn't allow us to remove directories that contain files or subdirectories. Functions like OS, RM, DI can only delete empty directories. Using shuttle module, we can remove an entire directory along with all its files and subdirectories in a single operation. It is more flexible, more advanced and especially useful when working with entire folders or large scale file operations. With shuttle you can copy individual files, copy complete directories including subfolders, move or rename files and folders, delete directories along with all their contents. Now let's dive into the practicals. Uh first we have to obviously import the module itself shuttle. Now we are going to start by copying files and directories. Let me ls. Now the OS module that we covered in the previous video has one obvious shortcoming. It does not allow us to uh copy files and directories. So we are going to start by copying a file. I'm going to copy this hello.py file. Let me copy the file name. Now type shuttle dot copy. Now the shuttle has a few options for copying a file such as copy copy to. Now we are going to use the copy to uh method because it not only copies the file, it also copies its metadata. Metadata is basically the details of a file such as its permissions uh last modified date and time ATC. So shuttle dotcopy to. Now we have to tell the copy to uh function two things. The file name that you want to copy and the destination directory where you want to copy. I want to copy this hello.py file uh which is in my current working directory. So let me paste it here. Comma. Now specify the destination directory. I'm going to copy in my same directory. So uh let's give it a name. Hello CP. cp py. So what the copy function is going to do? It will take this file and create a copy of it under this new name hello ccp. py. Now by default the copy command searches for the file in in your current working directory. So it will search for this hello.py file in my current working directory. If it finds this file, then it will make a copy of it under this new name in the same directory or in my current working directory. Let's uh execute the script. We have no errors or output. Now let's ls. As you can see guys, okay, as you can see, we have successfully created a copy of this hello uh pi file under this new name. Now uh we can copy a file to any directory. Let me copy this to my desktop. So right click uh uh in in desktop open in terminal. I want to copy my complete path to the desktop which is this. Now let's uh paste the path here and put r before the opening double quote so that uh copy to doesn't confuse the path separator backslash with a start of an escape sequence. This time I'm telling this copy to method that take this file which is in my current working directory then make a copy of it in my desktop or whatever path you specify. Let's execute the code and uh and we have no error. And let's check my desktop. As you can see guys here, hello this is a Python file. It has been copied. Now we can copy the same file under a new name as well after the directory name slash write uh the file name hello dot py. This time it will make a copy of this hello.py file in desktop under this new name. Let's execute the code. And here as you can see hello 12 has been copied to the desktop. So that's how you can copy a file. Now let's copy a directory ls. Uh let me check contents of the files. directory ls files. Inside the files, as you can see, I have all these files, right? So, what I want to do is make a copy of this files directory. So, patil dot copy tree. Now the you know to copy directories and uh uh their contents we have the copy tree function. Copy tree function not only copies a directory it also copies contents of that directory. Now let's provide the directory name that we want to copy. As you can see in my current working directory I have this files directory. I want to copy uh this files directory, and uh files one two. So what copy tree is going to do? It will take files directory in my current work from my current working directory and create a copy of it under this new name files one two. So all the contents of this files directory will be copied into this files one to directory l uh let's execute the script first ls as you can see we have the files one to directory let's check its contents files one two and we have successfully copied not only these files also its contents right and similarly you can uh copy a directory to any specific directory. Just provide the complete path and uh then it will copy the directory to that specific location or directory. Now let's see how we can remove a directory along with its contents. As we saw in the previous video, the OS module allows us to remove only an empty directory, right? uh we can't remove a directory with contents with OS module but with the shuttle module we can remove everything. Shuttle dot rm tree. Now rm tree is short for remove tree. It means it not only removes a directory, it also removes its contents. For example, ls here I have this directory called files one two ls files one two. Now inside the files directory I have all this content or these files. So I want to get rid of this files directory along with its contents. So within quotes specify the exact directory name which is files one. So, rm tree will remove this files one to directory along with its contents. Okay, let's execute the code and we have no errors. Let's say ls. As you can see the files one to directory has been removed. Similarly, you can remove a directory from any specific location or directory. Just specify the complete path to that directory. Now we are going to move files from one location to another just like the cut and paste. Okay. Sorry. LS. Let's say I want to move Hello CP from my current working directory to demo one two. So let's check contents of demo one two. Okay, it is an empty directory. Now function for moving is simply move. So specify the file name that you want to move which is hello cp for me. Now the second parameter must be a directory. So directory name is demo 12. So move uh is going to take this hello cp.py file and move it into this directory demo one2 which is in my current working directory. Remember this file is in my current working directory and this directory is also in my current working directory. So let's execute the code. Okay, we have no errors. ls as you can see hello cp is no longer here. But if I check contents of uh demo one two and it has been moved here. Now let's uh move this user data.txt to to my desktop. So let's copy the path to my desktop. pwd. This time the destination path is going to be this. And of course we have to specify r at the beginning. And make sure that your path is closed properly like this. This time I'm telling move function that uh take this file user data dot txt. Let me put it here first. So move function is going to take this specified file user data.txt txt and then move it into the desktop or whatever location you specify. Let's execute the code. Okay, we have no errors. But if I check my desktop, as you can see the file user data has been moved to the desktop. Let's ls we no longer have the user data.xt file here. It has been moved to the new location desktop. Welcome everyone. Now we are going to create some very useful Python real world projects in this and next few sections. These projects will help you apply all the concepts you have learned throughout this course in a practical and meaningful way. By building projects, you will strengthen your problem solving skills, improve your coding confidence, and see how different Python concepts work together. It's time to solidify your understanding of Python and start thinking like a real developer. Now, in this particular project, we will build a password generator that generates strong passwords. This is a simple project which is designed to help you understand the logic behind randomness and string manipulation in Python. As we move forward, the complexity of our projects will increase which will help you grow step by step as a Python programmer. So let's dive into the practicals. Now let's dive into the practicals and import the random module. We are going to use the random module to generate password. Now our program will give users the ability to generate password of their desired length. For example, if a user wants to generate password that is 15 characters long, then they should be able to do it. Okay. So, let's create a variable peng equal to input. Enter the password length. So this p length variable is storing the password length whatever uh password length the user wants. Now we are going to create a function that will generate the password. So function name is going to be pass gen. Now we are going to pass the password length as an argument to the to this pass gen function. Now let's define the passgen function. define passion. Now here this past chain function as you can see we are passing it the p length as an argument. So this argument needs to be accepted here. So p length. Now inside this pass chain function first we need to initialize a few variables. So first variable is going to be password equal to nothing. So we have created the variable password. It is equal to nothing. The reason why it has been initialized with nothing because this variable is going to store the actual password. We will be appending or concatenating the random characters that a random module is going to generate to this pass WD variable. That's why it has been initialized with nothing. Now let's create uh care set variable. The car set variable is going to store the characters that we are going to use to generate the password. We are going to use all the 26 characters. So type them in here. And of course we will be using all the 10 digits. And our password is also going to contain a special character. It is mandatory to have at least one special character in a secure password. Okay, that special character is going to be the underscore. So, underscore and hyphen as well. So, these are the characters that we will be using to generate the password. Okay. Now, let's create a loop for i in range. Loop will start from one and run up to the number that the user enters. For example, if user enters 12, then this loop will run uh 12 times and it will generate the password that is 12 characters long or whatever number the user enters. So second value needs to be the value that we have passed to this function. So here we are passing p length right and we are accepting this argument as a parameter here inside the passion function pen right. So write the password length here + 1. Now write password equal to password. Now this password variable as you can see this is the variable that I have initialized here. So make sure that you write that variable here. Password equal to again password plus now let's uh generate a random character. So random dot choice. Now the choice variable as we already know sorry the choice function of the random function as we already know it selects a random character from a given character set. We are going to provide it the care set variable. So care set the car set variable as you can see it is storing all these characters. Okay let's uh print the password variable then I I'll break down everything. Okay, password. Let's execute the code. Enter the password length. Let's say 12. As you can see, we have uh an error. Type error can only concatenate string not int at line number seven. Okay. Okay. Let's see line number seven. Okay. Okay. Here as you can see I'm passing the number that user enters to the pass gen function. Now as we already know the input function treats all inputs as a string. Whether you enter integers, decimal numbers or boolean data, it treats everything as a string. So we need to fix it and convert this string into an integer. It can be done right here or where you are asking for user input. So let's do it here. Int and close the int at the end like this. Now it should it should fix the error. Let's execute the code. Let's say 13. As you can see guys, we have generated the password. We are not there yet of course but we certainly have uh made some progress here. So let's break this down. It is important to understand how it is uh working in the background. So first thing that we are doing is asking user to enter password length. How long they want their password to be right? So whatever length or number user enters let's say here I have entered 13 that gets stored in the pen variable. Now we are passing the peng variable as an argument to passion. And here we are accepting that argument as a parameter. And here we have created these two variables. The password variable is storing nothing and character set variable is storing these characters. Right? Now here we have created this uh for loop. It starts from one and runs up to the number that the user enters. Here we have entered 13. So this loop will run 13 times. And on each run we are generating a random character then concatenating that random character to the password variable. Okay. So when this loop runs for the first time we are generating the first character. First Python resolves this particular part. So random dot choice. So choice the choice function is going to select a random character from this given character set which is car set. So car care set is storing all these characters. So on the first run it is going to select the first random character which is this. Right? On the first run the choice function selects the E character. Then we are concatenating password with the generated character which is E. Now the password variable for now is storing nothing. It is storing an empty value. Right? So here this addition operator it concatenates the e with the past wd variable which is storing nothing. So e gets concatenated into the pass wd variable. Then that uh concatenated value is stored in the past wd variable. Now the past wd is storing e and down here we are printing the e. That's why we have e in the output. And when this loop runs for the second time, the choice function selects one and then we are concat concatenating one to the past WD. Now pass WD is already storing E. So one gets concatenated with E, right? Then that concatenated value gets stored in the past variable. Now past WD variable is storing these two values. And when this loop runs for the second time, the choice function generates or selects the random character six and six gets concatenated to the password. Password variable is already storing these two characters. So on the third run, it is going to concatenate six to the pass WD variable and then we are printing that value here. So okay, so this loop runs 13 times. On each run it selects a random character. That random character gets concatenated to the pass WD variable. Right? So at the end as you can see it has generated the 13 random characters because the password length is 13. So this loop ran 13 times and on each run it selected or generated a random random character then concatenated them together. Now here it is important to notice that uh we are using plus to concatenate. When you use plus with two values, two string values, it concatenates them. Right? Okay. Let's uh check the length for the confirmation. Let's enter 12. As you can see, password length is 12. Right? Now let's print this uh password outside of the for loop uh for loops scope like this. Now we should only have the uh final password as you can see. Okay, that's it for this video. In the next video we will further refine this this code. Obviously this is a very incomplete program. We are going to continue where we left off in the previous video. In this video, we will perform some validation. Uh let me execute my code and enter let's say two. As you can see, the program has generated the password that is two characters long because that's what I asked my program to to do. However, a secure uh password has some minimum requirements, right? A secure password has to be minimum 8 characters long or maybe 10 characters long. So this is what we are going to uh do the next we will generate the password only if the user enters the number eight or more. Your password can't be less than 8 characters long. Okay. So let's write if sorry if p length is less than uh let's say 8 then we are going to print the message your password must be 8 characters long must be minimum eight characters long and then write the exit function. Now the exit function in Python exits out of the program. It terminates your program. Okay, so let me execute the code. Okay, let's enter let's say six. Press enter. As you can see your password must be minimum 8 characters long. Okay. So I entered six. Here I'm performing the condition check if the password length is less than 8. Now since I entered six, six got stored in the p length. So here I'm checking if p length which is storing six is less than 8. Condition is true. Right? 6 is less than 8. So condition was evaluated to true and the block of if was executed where I printed this message. Then here I'm using the exit function. So exit function exits out of your Python program. As soon as your exit function gets executed, your program stops right there. Your program gets terminated there. So now let's enter let's say eight. Your password must be minimum 8 characters long. Okay. Here what we can do is remove the equal to sign. Now it will generate the password that is 8 8 characters long. As you can see I entered eight. Now it has generated the password that is 8 characters long. So you must enter eight or more then it will generate password. that password. You can modify this value however you like. Maybe you want your password length minimum five. You can do that as well like this. If I enter five, okay, it is generating the password that is five characters long. But if you enter anything less than five then yeah it will show this error and ask you to enter password that is at least uh 8 characters long or however many characters you want. In the next video we are going to finish this program. Okay. Okay. We are continuing where we left off in the previous video. Now here I'm using the print function to print the password. Now I'm not going to print the password inside the functions block rather I'm going to return the password. So return return password. So I'm returning password back to the part where I'm calling the function. So down here I'm calling my function here right now. So password equal to pass gen and let's print the password let's say 12. Okay, we are uh able to generate and print the password. So guys the way it is working here at line number 18 I have uh this line password equal to pass gen which is a function. So, so first Python calls this function. Once a function is called, the execution moves to the part where you have defined the function. So, here uh we have defined the function. So, here Python generates the password then returns that password back to the passgen function where it has been called. It has been called here. Now we are storing the returned value which is the password in this variable called password. Then we are printing that uh that value here. Okay. Now we need to to do a few fixes. Let's say I want uh my password only in uppercase. So what we can do is uh password is storing the actual password right? So we have we can use the uppercase function to convert the password into uppercase characters as you can see right let's enter password that is 44 characters long okay so this way you can you know mix up your password you can use upper case and only lower cases as well now let's say I want to generate maybe 10 passwords Let's uh then write for i in range and loop is going to start from one and run 10 times 10 + 1. Now inside the block of uh for loop we need to call the function. Okay. So this loop obviously okay 10 + 1 it it is going to run 10 times. So when this loop runs for the first time we are calling the function right it uh this function generates the password then returns that password to the function then we are storing that password to the password variable and here I'm printing that password right as you can see we have generated 10 passwords right now when this loop runs uh for the second time uh it is going to repeat the same thing. It will call the function. This function will generate the password and return the generated password uh to the function pass gen. Then we are assigning the gen the returned value to the password again. And uh then we are printing that value here. So since this loop runs 10 times, this function gets called 10 times and each time it generates a new password and uh yeah, then we are storing that password here and printing that out like this. Let's generate let's say 20 passwords. Okay, sorry. This is the password length. So it has generated 10 passwords that are 12 20 digits long. If you want to generate let's say 20 passwords then you have to provide that value to the here to the for loop like this. Now this will generate 20 passwords and one important thing before signing off is this return value. Now make sure that you return the password outside of the block of for loop like this. Okay, this as you can see here I'm returning it outside of the for loops block because here it is going to return the complete password. But if you put the return uh inside the for loops block then it will create problems as you can see. So what basically is happening? So when this loop runs for the first time it generates the first character and gets stored in the past wd variable. then it is returning that generated character to the function. Then uh we are you know storing that here and printing it out. So the rule of the return return is that as soon as the return gets executed it will not execute any lines after it and control immediately moves to the part where the function has been called. Okay. So make sure that the value is returned outside of the for loops structure. This way it will return the complete password like this. So yeah guys that's it for this small project. Let me know if you have any questions and of course you are absolutely free to improvise this project and add the features that you that you want. This project is an extension of our previous project. Now we are building a MAC address address generator that can create either a single MAC address or multiple MAC addresses at once. This program requires a bit more complex logic than the previous one because it involves grouping characters into pairs and also managing separators. This will enhance our understanding of loops and string manipulation in Python. So let's dive into the practicals now. Let's dive into the practicals. Before writing the code, let me uh let me show you how a MAC address looks like. So press Windows key and type PowerShell. Click on PowerShell 7 or 5 whatever appears the first. Now uh type the commandlet get- net adapter. Press enter. This get net adapter. Commandlet lists all the installed network interfaces. Now we need to check out this MAC address column. These are the MAC addresses right for each interface. A MAC address contains 12 hexadesimal digits and uh the hexadimal digits are grouped into the pairs of two. So we have six pairs of these hexadesimal digits and pairs are separated by hyphens. As you can see, however, on Windows and Linux, these pairs are separated by columns. So, what I'm going to do is copy a MAC address and uh put it inside my code editor. Now, here we need to use a bit a bit of logic, right? We have to keep track of of digits. So after every second digit we have to append this hyphen character to the MAC address. We are going to use the random module to generate MAC address or addresses. Now I'm going to create a function that will actually generate the MAC address. So MAC gen MAC generator. You can give any name to your function of course. Now let's define this function. This function is not going to accept any arguments. Arguments are not required for this function. So define. So let's define mac gen. We need to create a few variables. So first variable is going to be mac header equal to nothing or an empty string. This MAC adder variable is going to store the actual or the final MAC address. Now uh let's create a variable called count. Count count equal to zero. Now this count variable is going to keep track of pairs. So after generating two digits, we are going to append this hyphen character to the MAC address. So this count variable is going to count these pairs. So after every second digit we will have to append the hyphen character. Now write uh create variable called care set. Car set variable is going to store the characters that will be used to generate the MAC address. As you can see a MAC address is made up of hexadimal digits. So write the hexadimal digits. Write all the nine sorry 10 digits from one to uh from 0 to 9 and six hexadesimal digits or characters from A to F A B C D E F. So this is the character set that we are going to use to generate the MAC address. Now let's create a loop for I in range. This loop runs 12 times uh because a MAC address contains 12 digits. So we will have to generate 12 random digits. So on each run this for loop is going to generate a random hexadimal digit. So from 1 to 12 + 1. Now write Mac adder equal to now this MAC adder is the variable that we have initialized here for now it is storing an empty string. So MAC adder equal to Mac adder plus now let's generate a hexadimal digit. So random sorry random random dot choice. Now the choice function as we already know it selects a random character from a given character set. Now we are going to give it this character set and this is stored in the variable care set. So I'm going to copy the variable care set and put it here. Let's print the MAC header. Let's execute the code. Then I will break down everything. Okay. Okay. It is working just fine as it should. So it has generated 12 hexadesimal uh digits. So this loop runs 12 times. Right? So when this loop runs for the first time, MAC adder is equal to Mac adder plus random dot choice. First Python is going to resolve this portion. So here the choice function will select a random character from this given care set. Right? From this given care set. So on the first run it selects four. Now after selecting four it is going to concatenate four with the mac adder variable. Now mac adder variable for now is storing nothing. Now after concatenating nothing with four the value of mac adder variable becomes four. So that concatenated value is assigned to the mac adder variable. Now we are printing the macader variable that's why four got printed. Now when this loop runs for the second time the random choice function selects the second digit which is 8. Right? Now this 8 is concatenated into the mac adder variable. Now mac adder is already storing four. Right? So 8 get concatenated with the four. Now this concatenated value is assigned or stored in the macad variable. Now macad variable is storing 48. So we are printing 48. Here on the third run it selects random dot choice selects seven right and seven gets concatenated to the existing values 4 8. So it keeps repeating this process uh 12 times because this loop runs 12 times. On each run the random dot choice function selects a random character and then we are concatenating that random character to the to the mac adder variable. So therefore at the end we have this complete number that is 12 hexadimal digits long because this loop runs 12 times. Right? So yeah, we have created our core program and in the next video we will append the hyphen after every second digit. Okay, so that's it for this video. I'm going to resume where I left off in the previous video. In this video, I'm going to append this hyphen after every second digit like this. Right, I have created count variable for this particular purpose. it is going to keep track of the digits right after every second digit we will append this. Okay. So inside the for loop make sure that you have uh the count variable being initialized to zero and inside the block of for loop we need to count this variable by one. So count equal to count + 1. So what is going to happen whenever this loop runs on each run the value of count will be incremented by one. So let's check if count equal to two. So when the value of count becomes two we are going to append the hyphen to the mac adder variable. So, MAC adder equal to Mac adder plus let's append this hyphen. Okay. So, first let's execute the code then I will break down everything. As you can see after uh second digit it has appended hyphen. However, it has not appended it after other pairs right? It is only working with the first two digits or the first pair. Why? Because when this loop runs for the first time at line number 11, we are incrementing value of count which is zero by 1. So count + 1. 0 + 1 becomes 1. Now the value of count is 1. Here the choice function is going to uh select a random character and store that in the macad variable. Right here I'm checking if count is equal to two. It is false. Counts current value is one. So one is is not equal to two. So this block will not be executed. And here we are printing e. Now control moves back to the for loop. Here it will again increment the value of count by one. The current value of count is 1. So 1 + 1 becomes two. Now the count's value is two. And uh here choice is going to select a random character which is zero. and uh concatenate it with the MAC header which is already storing E. So MAC adder is now storing E and zero. Now here I'm checking if count is equal to two. Condition is true, right? Count's current value is two. So 2 is equal to two. Since this condition is evaluated to true, the block of if is executed. Now inside the block of if I am appending MAC adder equal to Mac adder plus hyphen right so hyphen gets appended to this MAC adder variable which is this. That's why we have the hyphen here. So we are printing it here. Now when this loop runs for the third time value of count becomes three. So this random choice selects the third character and it gets appended to the MAC header. Now condition is false. Count whose value is three. Three is not equal to two. So this will not be executed on the fourth run. The value of count becomes four. It choice selects the fourth character and it gets appended to the macader. And here I'm checking count whose value is four equal to two. Condition is again false. So the problem here is with the count variable. So what we need to do after the value of count reaches two. We need to reset it. Uh inside this uh if conditions block, we are appending the hyphen to the MAC header if the value of count reaches two. Now we need to reset it to zero again. Okay. Uh so when value of count reaches two we are appending the hyphen to the macader variable and then resetting or reinitializing the value of count zero so it can track the next two digits. So this time it should uh fix the error. As you can see guys now after every second digit we are appending the hyphen. Okay we have hyphen at the end as well. Uh don't worry about it. It will be fixed later. So we are getting closer. Right in the next video we we will clean up and format our MAC address. We are going to continue where I left off in the previous video. Now first thing that I'm going to do is uh I don't want to print the every character uh that this uh this function is generating. So remove the print function and I'm going to return the MAC address like this. Okay, make sure that the return statement is outside of the for loops uh for loops block like this. Now let's uh print the value that that is being returned. Okay, it is returning a MAC address, right? As you can see. Now, what I'm going to do is uh assign the returned value to a variable MAC equal to print Mac. Now I need to get rid of this particular part, right? This is not required. So Mac I'm going to slice this last portion minus one. Now we have the desired output. Now MAC address as you can see the letters are in uppercase. So what I'm going to do is convert the lowerase characters into letters into uppercase using the upper function. And we have successfully converted the lowerase uh letters into upper case. Right? Now let's generate multiple MAC addresses. So what I'm going to do is uh write a for loop. Uh I want to generate 20 addresses. So 1 20 + 1 and write these two lines inside the block of for loop like this. Let's execute the code and we have successfully generated 20 MAC addresses. So the way it is working this loop runs 20 times right. So when this loop runs for the first time here I am assigning MAC address equal to MAC variable. Now MAC this is obviously a function. First Python is going to execute this function. Here we are calling the function. First Python is going to call this function control moves here where we have defined the function and here it will generate the MAC address then return the generated MAC address to the function. Then I'm assigning the returned value to the MAC variable. And here I'm slicing the last character from this variable which is uh which is this right? If you remember at the end we had this unnecessary hyphen. So it basically slices the last character. Then I'm using the uppercase function. So uppercase function is going to convert all the lowerase letters to uppercase that's why we have everything in uppercase. So we have successfully generated created the MAC address as well as we are generating 20 MAC addresses. And this way you can generate as many MAC addresses as you like. Just write that number in the loop. This time uh this for loop runs 10 times. So it will generate sorry this loop runs 100 times. So it is generating 100 MAC addresses. So on each run this function gets called. It returns a MAC address. Then we are printing that that MAC address. Now let's take this one step uh forwarder. I'm going to save the MAC addresses in a file. Okay. So here we are generating these MAC addresses but uh we are not saving them yet. So let's save them into a file. Okay. So let's create a function called save. I'm going to pass it the MAC variable. Now what is the MAC variable? It is storing the MAC address that this function returns. So here I am calling the save function and passing it the MAC address and then this MAC address will be saved in a file. So define save and Mac with open and uh file name is going to be MAC addresses dot txt and uh it is going to be a append. we are going to uh open the file in the append mode because we want to append each each new MAC address at the end. If you write simply W then the new MAC address will replace the existing MAC address. So instead we are going to use a it will append each new MAC address at the end as file. Now file dot uh write and write mac plus slash n. This is a new line character. It will create a new line character after appending uh a MAC address. Right? We have already done this in the file management section. Right? And here this MAC address.xt file will be created in my current working directory which is Python. If you want to store or create a file in a specific location, then specify path to it here. Okay. So let's first verify the code if it is working or not. Okay. So as you can see it has printed all the MAC addresses. We have we are generating 100 MAC addresses. Now let's check the file if it has been created or not. ls. Okay. We have the file called MAC addresses dot MAC addresses .txt. This is exactly what we created. And let's get out its contents. Notepad sorry Notepad MAC addresses.txt. As you can see guys, inside this file we have saved all the 100 MAC addresses. Okay, we have a problem here in this file. The MAC addresses that have been saved. We have unnecessary hyphen at the end. We need to get rid of them. Let's see what the problem is. Even though if you check the output here in the output, we don't have uh the additional hyphen. Okay. Okay. I see the problem. Now I am here. As you can see, I'm passing this unformatted MAC address to the save function. Right? So, what I'm going to do is get rid of print. It is not required. MAC equal to this. Okay. Let me remove the existing MAC addresses. Now this time we are not printing any MAC address addresses. Okay, let's uh reduce the number to 10 and let's actually print the MAC addresses. Okay, we have generated 10 MAC addresses ls. Okay, we have file here notepad and inside the file now we have the exact output we wanted right okay we have saved the MAC addresses in a clean and uh and its correct format so let me quickly walk you through this entire program's flow here this loop runs 10 times when this loop runs For the first time I'm calling this MAC gen function. So MAC gen function generates a MAC address and returns that address to the MAC gen function. After uh it receives the value then we are assigning that value to MAC. And here I'm formatting the received MAC address. Right? First I'm slicing or removing the unnecessary hyphen from the end. Then converting lowerase characters or letters into uppercase. Then assigning the formatted MAC address to MAC. And then I'm printing the MAC address uh uh to the output console. And at the line number 29, I am calling the save function. Right? I'm passing the MAC address to the save function. I'm basically telling my save function take this MAC address then save it into the file when the save function gets called. It has been defined here. Now here I'm creating a file called MAC addresses dot txt in the append mode. So each new address MAC address gets appended at the end. Now here I'm writing the MAC address to the file. And here we have the new line character which will make sure that each new address is MAC address is appended in a new line. Okay. After finishing this execution control returns back to the for loop. The for loop runs for the second time. It repeats the same thing. Calls the max gen function. It returns a new MAC address. Then we are formatting that passing that value to the save function. It saves that MAC address in a new line. So it keeps repeating this as long as this loop keeps running. Okay. So let's uh increase this value to let's say 100 and see if it saves all the MAC addresses. And it has generated 100 MAC addresses for sure. Let's check the file and in this file it has saved all the MAC addresses. So guys, that's how you can basically put everything together to create, you know, Python programs. Let me know if you have any questions. In this section, we will explore networking using the socket module. You will learn how to build network applications that communicate over the internet with servers and remote systems. This includes establishing server connections, verifying network connectivity, and developing practical tools like port scanners. Python provides a powerful built-in module called socket for handling networking tasks. It is widely used by network administrators, system engineers, and cyber security analysts to enable communication between systems using standard protocols. And of course, it is heavily used by programmers to build network ccentric applications. In simple terms, the socket module allows Python programs to send and receive data across a network. Using it, we can build client server applications, exchange data, and interact with network services through protocols like TCP and UDP. It also helps you understand key networking concepts such as how connections are established. Now, let's dive into the practicals. First we need to import the socket module. Now in the try block we will try to try to establish a connection with a remote host. So try now write sock we are going to create a socket object. Sock equal to socket. Socket is the module of course dot socket and socket is the function inside the socket module. The socket module creates a socket object. Within the parenthesis, we need to specify two parameters. Socket dotf inet. The second parameter is going to be socket dot sock stream. So we have successfully created a socket object and assigned it to the sock variable. Now the first parameter is this socket AFET. AFET represents the IPv4 address. As we already know the IP address family has two two primary versions. IPv4 and IPv6. So here I'm telling my socket function that you are going to use the IPv4 address to communicate with the host. the host that we are going to provide or specify in a minute. So, AF Inet represents the IPv4 address. And if you want to use IPv6 address, then you can write in 6 like this. Now, the socket function is going to use the IPv6 address. However, we are going to use the IPv4 address because it is still the most widely used version of the IP address family. IPv6 is relatively new. It is not exactly new but still the IPv4 address is the most popular and dominant. The second parameter that we have is this. This is called this communication protocol. Now the sock_stream it represents the TCP protocol. TCP protocol essentially makes sure that the data is delivered to the destination. So that's why we are using the TCP protocol because here we are trying to establish a connection with the remote host. So we need a reliable protocol that can guarantee the data delivery. So we have configured our socket object with these two details. Okay, it is going to use the IPv4 address to reach out to the server and TCP protocol to guarantee the data delivery. Now using the sock variable, we can attempt a connection with the remote host. So dot connect. Now the connect function accepts parameters in the form of tupal. Tupal is defined by parenthesis. Right? So inside the parenthesis of connect, write uh parenthesis and now specify the host uh or domain that you want to connect to. I'm going to connect to google.com sorry now comma and specify a port number 443. So here sock what is sock? Sock is a variable which is storing this socket object and we have configured the socket object with these details. Right here I'm telling my socket function that you are going to use IP4 address and TCP protocol. So connect function is going to use these configurations to connect to the specified host google.com on port number 443. Now connect function will uh try to connect or establish a connection with the google.com. Now how does the connect function work? What does uh it actually mean when we say that it establishes a connection with the google.com? Here guys, we need to uh to understand how computers communicate over the internet. I will give you a very brief overview of how it works because if I attempt to explain uh in detail technically it will take not a separate video rather a separate computer networking course. I will try to brief it so everyone can understand. Now before you access any server on the internet first a connection must be established between the client and server. Client is the system that is trying to access the server. In in my case, my system is client because here I am trying to access the uh google.com or Google's server. So, first connection must be established between the client and server and after a connection is successful then we can start accessing that server. In our case, I'm trying to access google.com. So first before I can access the google.com first a connection must be established with the google.com or Google's server to be specific only then I will be able to search on google.com. Now the connection is established by something called three-way handshake in the background. Three-way handshake is part of the TCP protocol that we have specified here. In three-way handshake, both client and server exchange three packets between them. In those three packets, client and server must agree on several things or parameters such as which security protocol and algorithms they must use to secure data, how much data should be sent in each packet among other uh details or configurations. Once both client and server agree on all the parameters, the connection gets established and then we can start accessing the google.com. Now this three-way handshake happens automatically in the background without our interference. Right now once both client and server agree on all the parameters or configurations then the connection get established. Now we can start accessing the specified host which is google.com in our case. Now uh let me write uh connection successful. So if everything goes well the connect function is going to connect to the google.com. Then if connection is successful then it will uh print the connection successful message. Now in the accept block we are going to catch the errors. So except socket dot error. The socket dot error exception is going to catch the error. If the connect function for some reasons is not able to connect to the host then it will raise a runtime error that we are catching here in the accept block print could not connect. Now the obvious question here is when a connection will not be a success or when connection can't be established. Well, there are many reasons. For example, if the host name that you specify here, if the host is down or not available, then connect function will not be able to establish a connection, then the control will immediately move to the the accept block. Or if the port number that we have specified here is either filtered by a firewall or closed then also the connect function will not be able to establish the connection to the host and the accept block will be executed or if your internet connection is not working then the connect function will not be able to establish a connection with the host and the accept block will be executed. So except block catches all types of runtime errors. So let's execute the code and see what we get. As you can see guys, connection successful because google.com is it is up and running and port number that we have specified is 443. The 443 is the default port for HTTPS or secure websites. That's why we have specified the port number 443. So connection was successful. Once the connect function uh establishes a connection successfully then Python prints all the lines that we have written in the try block. It will execute everything that you write after the connect function. Here we have written this print statement. Right? Now what happens if I specify another port let's say 21. Now 21 port number is typically closed. In such case, the connect function will not be able to establish a connection with Google successfully because port number 21 is closed. So let's run the code. As you can see guys, it is taking much longer than the previous execution because the connect function is trying to reconnect on the port number 21. As you can see could not connect because port number 21 is closed. Therefore, it could not uh establish establish connection with the google.com on this specific port. So, we have the message could not connect the accept block was executed. Now, one thing that we can do to optimize our code is set the time out. So, sock dot set timeout specify the seconds let's say two. Now, what does this set timeout does? Well, the way it works is if the connect function is not able to establish connection with the specified host within the 2 seconds or whatever number you specify then it will move on. It will execute the accept block. The way the connect function by default works is if in the first attempt it is not able to establish connection then it will reconnect. it will try to reconnect. It does it for several times which is which can be problematic because it can freeze your program or make it slow. But here I'm telling my program that you are only going to attempt connection for 2 seconds. If you connect within 2 seconds then it is good. If not then we will move on. The accept block will be executed. So let's uh rerun this time. As you can see this time our program was executed quickly. So connect function only attempted to connect for 2 seconds and within 2 seconds it was not able to establish the connection. So accept block was executed. Now let me comment this out and execute it again without the set timeout. As you can see, it is going to take a much longer to to execute because connect function is trying to reconnect to the google.com on port number 21. It is attempting multiple connections which is leaving our program hanging as you can see which is very problematic for most real world applications as you can see. But with the set timeout, we can actually tell connect function for how long it should try to connect. So yeah, that's how the set timeout function works. Now guys, never forget to close the connection in the finally block. So soft dot close. So close function is going to close the network resources after a connection is successful. So it is a recommended practice. Okay. Make sure to spell the finally correctly. Doublel. It will not have any visible impact in our output. But in the background it will close the the network resources being allocated to the connection once the connection completes. And I almost forgot that here I have used sock.stream which represents the TCP protocol. We can also use UDP protocol. UDP protocol is uh uh is represented by sock sock DG RAM. However, the UDP protocol is used for very specific applications. For example, if you are building a real real-time applications like uh a chat system or live streaming, in such cases, we use the UDP protocol. For 95% applications, we use the we use the TCP protocol which is represented by sock_stream because TCP protocol is a reliable protocol which guarantees the data delivery. Here since we are trying to establish a connection with google.com, we need a reliable protocol that can guarantee the uh data delivery. This is exactly what the TCP protocol does. Let me know guys if you have any questions. In this video, we will dive deeper into the socket module. Specifically, we will learn about the get host by name function. Get host by name performs DNS resolution. It takes a domain name and returns its corresponding IPv4 address. Every website or domain such as Google or Facebook has at least one IP address assigned to it. For example, when you type google.com into a web browser, a protocol called DNS translates that domain name into its IP address. Your system then communicates with Google using that specific IP address. These domain names exist only for human convenience. Computers actually communicate using the IP addresses. There are many tools available that allow us to quickly find or retrieve IP address of any website. Now in the Python socket module has the get host by name function which allows us to retrieve the IPv4 address of any website easily. Now let's dive into the practicals. So in the try block we will attempt to retrieve IP address of a domain name IP equal to socket dot get host by name within the parenthesis specify the domain name whose IP address you want to retrieve. I want to retrieve IP address of Google. So get host uh by name function needs one parameter. You have to tell it the domain name or the website's name whose IP address you want to retrieve. So after it uh retrieves the IP address, then uh it is going to assign that IP address to the variable IP. So print let's print IP. Now in the accept block we are going to catch the error if it raises any errors. Except socket dot G ai error. G AI stands for get address information and if it is not able to retrieve the IP address of the specified host then that error will be caught in the accept block. Uh we are going to print uh the error message. Please provide a valid domain name. Let's execute the code. As you can see guys, we have successfully retrieved the IP address of the specified host google.com. This is the IP address of google.com. So what I'm going to do is uh copy this IP address and paste it in uh in browser. Let me paste it here. Press enter. As you can see guys, it has automatically redirected me to the google.com because this is the IP address of the the google.com. Similarly, this way you can uh retrieve uh IPv4 address of any website or domain name on uh on internet yahoo.com. This is the IP address of yahoo.com. Right now, what happens if you specify an invalid domain name like this? This time it will raise an error. Let me execute the code. As you can see, please provide a valid domain name. So, what is happening here? See guys, every website or domain name on the internet has at least one IP address assigned to it. So, here I have provided an invalid domain name. Since this uh domain or website doesn't exist on the internet, the get host by name function was not able to retrieve its IP address. Since it was not able to retrieve its IP address, it raised a runtime error. That error was called here in the accept block. So guys, that's how it actually works. I hope guys it is clear. Now let's retrieve IP address of x.com former formerly known as Google. uh sorry Twitter as you can see this is the IP address of x.com now guys this is going to be very important uh later in our project that we will build later here we are basically validating a valid domain name right to validate a domain name in a Python program it is simple we use the get host by a name function right it will retrieve the IP address of a domain name if that domain name uh exists on the internet but if you provide a domain name that doesn't exist then it won't be able to retrieve IP address of that domain name and raise an error now in the background this get host by name function uses something called the DNS DNS protocol is responsible for resolving a domain name to its corresponding IP address. So in the background it is the DNS protocol that actually fetches the IP address of the provided host. Then we are assigning that to to the IP variable. So guys if you want to learn about you know the protocols that I'm discussing in this uh uh in this section like TCP, UDP or DNS then I have covered all of them in my cyber security course uh using animations. Okay. Okay. So, feel free to check that out if you are new to computer networking. And of course, you don't you don't need to enroll in my course. You can use any any other resources or courses on Udemy or other platforms because computer networking is a must for especially for networking engineers, uh, cyber security analysts, cloud engineers or even for programmers in general. So, thank you very much guys. In this video, we are going to check our internet connectivity to determine if we are online or offline. Now, let's dive into the practicals and the program is going to remain almost uh the same uh as we did in the previous video with the with minor modifications. So, first of course we need to import the socket in the drive block. we will attempt to establish a connection with uh a reliable host like Google. So let's create a socket object. So socket dot socket function socket dot af_inet comma socket dot sock stream we are going to use the TCP protocol to make a connection and here I'm using IPB version 4 uh to create a connection with the host and sock dot connect now parenthesis again because as we already know the connect function accepts parameters as the tupal. So I'm going to connect to google.com on port number 443. So when you create an application that checks internet connectivity, make sure to specify a reliable host or the remote host name that is always up and running just like Google because Google is almost always you know up and running. It is never down. So if connection is successful then we are going to write the message you are online and uh let's define the accept block socket dot error print you are offline you are offline and of course finally also needs to be defined. Even though finally is optional but it is mandatory when it comes to the program optimization. We need to close the network connection sock.lo. So what is happening here? As we already know if the connect function successfully connects to the specified host then connection is a successor. However, if connect function is not able to establish connection uh with the specified host, then it raises an error. There are several reasons that connect function may not be able to successfully connect uh with the specified host, right? such as uh uh the host name that you provide here is not up and running or the port number that you specify here is either filtered by a firewall or closed or the most importantly if your internet connection is not working or if you are offline then also connect function will not be able to establish connection with the host because it is pretty obvious right in order to communicate with the devices on the internet you need to have a working internet connection. So if your internet connection is not working, connect function will not be able to reach out to the host and it will raise an error then that error will be caught in the accept block. So we are writing this message. For example, let's uh uh run the code. Uh okay. Okay. We have an error here. During handling the above exception, another occurred module socket has no Okay. So we have the attribute error module socket has no okay looks like there is a spelling mistake at line number four. Okay, socket it is socket. Sorry guys, socket. And of course, guys, we need to set the time out. Sock dot set timeout for 3 seconds. So if connect function is not able to uh establish connection within 3 seconds then we will exit out of the try block and accept block will be executed and you are online. As you can see the connection was uh made almost immediately. Now what I'm going to do is uh uh disconnect or discontinue my internet connection. Let me disconnect and let's uh run the code. As you can see guys, you are offline, right? We got the the output immediately. So what I would like to do is delay the output a little probably by a second because this way it looks almost you know it doesn't look uh that user friendly as you can see. Okay. So, what I'm going to do is import time. And here time dot sleep by 1 second. As you can see now we have a delay of 1 second. Then we get this message you are offline. So when the execution goes inside the accept block first we are using the time dots sleep method right it will delay your execution for 1 second after 1 second it will print the message you are offline so that's how you can check your internet connection okay like I said earlier the program is pretty much same as we did in the first video the only thing that you need to be careful about when checking internet connectivity is specifying a reliable host that is 24/7 up and running that is google.com or or similar website. So now let me uh connect to the internet and uh re-execute the code. As you can see you are online now. It is working as it
Generated algorithmically for Search Engine
Indexing.