[Music] python is more than just a programming language it is also a great place to begin if you're just starting to code with the popularity and versatility that python bags no wonder it is a great time to Learn Python Programming hi I welcome you all to this full course session on Python Programming and what follows is hopefully a crash course of everything that you need to know to start out with python but before we begin let's talk about our agenda for today so we're going to start out by introducing you to python here we are also going to talk about and overview of python also we're going to give you a guided way of becoming a python developer now next we are going to talk about the step-by-step installation of a python IDE and we're going to also help you run your first Python program across various idees now next we're going to talk about python Basics here we're going to talk about comments variables data types and operators in Python now followed by which we're going to talk about a few popular python libraries like numpy and scipi now next we're going to get a little deeper here we're going to talk about file handling and functions in Python we also going to discuss Concepts such as objectoriented programming classes and inheritance in Python now followed by that we have our final topic which is web development and web scraping in Python here we're also going to talk about Frameworks associated with python like Jango flask and web tupy with that I come to the end of the agenda also kindly take up this time to subscribe to us and don't forget to hit that Bell icon to never miss an update from the edura YouTube channel also check out our Python Programming certification course the link to which is in our description box below so without Much Ado let's get [Music] started python has been ranked the number one programming language in in Tob index and has been used by some of the largest companies in the tech industry like Pinterest Spotify YouTube Instagram Etc so you looking to Learn Python might just be the best decision you've ever made what is python python is an easy tolearn powerful language it has efficient high level data structures and a simple but effective approach to objectoriented programming Python's elegant syntax and dynamic typing together with its interpreted nature make it an ideal language for scripting and Rapid application development in many areas on most platforms and with that we can see why we use Python right the number one point will be the applications python is a very verstile programming language ranging from application development to web design game design uiu development data science machine learning automation Etc there's also the point of simplified syntax if you usually work with languages like Java C++ Etc you'll get me python is one of the simplest languages you can learn and this fact doesn't impact any of the features it is just as good as all the other options that you have and the only thing is it's a lot simpler the third point is wellb built packages now don't worry if you don't know what packages are I'll cover that later the only thing that you need to know right now is that packages have the ability to replace hundreds of lines of code with just a single line of code I'll show you how to do that later in this video and the fourth point that I want to stress on is the highly supportive Community look I get it programming is not always easy and you get stuck sometimes but with Python's Community you get a lot of support for the issues that you face and I'm telling you it's one of the most engaging and interactive communities that have ever come across [Music] now let's get started with the python installation so first let's go to Google and type python download over here click on the first link and you can see the download option there as well as the latest version 3.1 2.4 for Windows just click on download and below are the options on whether you should download it for Linux Mac or others and once it's downloaded click on it and you will be able to install Python and and the version and over here you will have to click on the option which are user admin and add the python part and then click on customize installation and over here just check if all the check boxes are clicked and then click on next and over here in advanced option just make sure the install python 3.12 for all users are clicked and this is your location then click on install and then the setup process will start so let's wait for it now that your python installation is successful and now if you want to check you need to open the comment prompt so just search for the comment prompt and over here let's type the python version so python hyphen hyphen version and click enter and as you can see the screen you will get the version of python displayed so now let's move on to download pyam in Windows and how to run a simple hello world Python program in our pyam ID so let us get started just go to Chrome and type pycharm download and over here just click on the first link so now we are on the official site of jetbrain so there will be an option below like to install it for Windows Mac and Linux so as we have Windows let's download it for Windows and you can see it is for pyam professional but it is a paid version so if you scroll down you will see a pyam Community Edition so we will download this as it is an open source so just click on the download button and the download will start and let's wait for it to download So once it's downloaded just double click on it and open it so now let's do our python setup over here click next and it will show the installation location and keep the same location as it requires 1.7 GB space then then click next and you will have an option to create a desktop shortcut so click on that and click on the update content menu too so that you can open any folder as a project then make sure to click on pi and the updated path version then click on next and you will get the start menu folder so there you can see the installation so click on that and after completing the python setup the setup will begin as you can see the screen the setup is completed so just click on finish so now let's search for pycharm and connect python with pycharm so open pycharm and you will get an option below as I confirm so click on that and continue and then you will get data sharing then click on send and then the python will open for the first time and you can see projects so click on the new project and if you you want to change the name of the project you can change it in the location bar now so let's name it as a new project and over here we will set the environment so for that select the virtual environment and then in the base python you will get the python version to check if you have the new version if not click on the three dots and go to the program file where you have saved python click on that and then you can see python.exe file so just click on that and click okay now you can see that you have connected python with python so then click on create as you can see the screen now you can see the project so click here for the menu and then you can see our project and the environment now we can run our first Python program and over here right click on the new project and go to new and select python file directly now it will take you a while to file an extension and over here just give a name as a demo and go to python file and press enter and you can see it's saved as a demo. py now you can directly run your first project so let's print hello world program so simply type print function and inside the double code just type hello world and let's run the code go over here and just click on it and and as you can see the screen the hello world is printed successfully now let's move on to print some numbers so just type print and give any random number like 2 4 6 so let's run it so as you can see the numbers have printed successfully on the screen now let's take up a simple program so now let's print a floating Point number so just type print and give a floating point Point number that is 3.14 so let's run it as you can see it's printed successfully hope you all have got an idea on how to install Python and python BYO and running your first hello world program before we move ahead with our next module I have a simple question for you guys and the question is which of the following best describes Python's programming level and the options are option a lowlevel language option b middle level language option C High LEL language and option D Assembly Language if you know the answers comment down in the comment section Below in the previous module we covered the introduction to Python and its installation we will now move on to the basics of programming and explain why learning python is important so first of all let me just give you a brief overview about how we use it and how it has come into existence so Python Programming Lang language is one of the most popular language much of the popularity has been through the data science application that it comes with the implementations using machine learning and artificial intelligence it was founded in late 1980s by guer one rossom and python is a highlevel interpreted language which can be used for both procedural and objected oriented programming language so first we are going to talk about the variables guys and variables are nothing but you know exactly the same as any other programming language if you have you know worked on any programming language like Java or C++ so a variable basically storing a value that may change in the future which the name also suggests guys so let's let's try to understand variable using an example let's say so I have certain commodity let's say which keeps changing because I you know for that let's put the commodity as a bunch of apples I have at home so I'm going to use a variable let's say apple and it is basically storing the values of how many apples I have so after each step we will take these steps as you know the steps of the execution of a program similar so let's say in one hour I'm eating one apple and I have 24 25 apples so the variable that I have put the value in is kept changing for 24 hours but it's not necessarily true that I will be only eating the apples I might add value to that variable as well so this is just a simple example guys I'm just storing a particular value inside a variable not necessarily the apple one we can think of an complex one as well so let's say a bank account you know like how money keeps coming in and coming out but uh account balance can be that variable which stores the value of how much money you have in your account that is also one variable guys so let's take it up to jupyter notebook guys and we'll see how we can work with variables in Python so I'm going to show you how you can declare a variable and discuss a few naming conventions rename this and uh just to be clear guys this is beginner tutorial so if you already know how you know these basic concepts work can move further in the video where I have discussed exception handling and there are fin handling Concepts and multi-threading classes and objects as well all right so the very first thing let's take a variable okay we are going to use variable only so this is my variable I'm using this is equal to sign we're going to discuss this in about a minute guys so I'm giving it some value and I'm using these inverted comma also so I'll talk about this as well so this is how simply I have given the variable name now I can use a method this is a predefined print method that I can use to return the value so this is how we get the value from the variable we're using the Sprint method method is basically a function I will discuss this as well and uh so let's talk about naming convention so naming conventions are nothing but you know certain rules that you have to follow while declaring a variable so these are some of the conventions that you should follow to write clean code right so the very first rule or convention that you have to follow follow is the variable name cannot start with a number right so it can only start with a character and underscore you know letter so I'll just show you guys so let's say if I want to write it like this and give some value I have a syntax error which says invalid syntax because this is written in the naming convention you cannot declare a variable like this all right so let's try with an underscore and we're good to go double underscore we are also good to go any other symbol all right so we will have a syntax errow all right guys after this the second convention is variables in Python are K sensitive which means is if I have a variable like this which is starting from know an uppercase letter V and we have this variable which starts from a lowercase letter V what happens is these are two different variables guys all right so I'll just change this value so that we have a clear picture so I have variable which is giving me the output some value and now if I right upper case letter V I have different variable guys so which means variables in Python are case sensitive so this also you should always remember because while declaring a variable sometimes you might miss you know these certain points while declaring a variable let's say you start with uppercase letter and then again when you are calling that variable you might not remember that you have basically declared the variable with a uppercase letter or lowercase letter that you should always keep in mind while writing the code and after that there is one more convention which is they can only contain Alpha numeric characters and underscores all right so we have variable if I write it as this it's good if I write it as this it's good we have a syntax error guys so alpha numeric characters only we can use and after that there is also one more rule which it says no special characters are allowed so this is all about variables guys and I've told you about the naming conventions as well so now what we'll do here is we will talk about operators in Python guys and I'm just so operators in Python are used in order to perform a task between variables or any two values or it could be one value as well so depending on the operation that the uh you know the output will vary and depending on the operation also we're going to use specific operators there are different types of operators in Python that we have so let's talk about those operators guys first of all we have assignment operators which is basically used to assign some value you know just giving an assignment to any variable or any value so when I say variable is equal to some value I'm actually using an assignment operator guys which is basically because I'm using this particular operator assign a value to a variable so that is how it works the assignment operators let's say I'm taking a variable value one over here so if I write variable is equal to variable + 1 this I think most of you must be aware if you have come from programming background so I can write this particular sentence because variable will now become two so instead of using this I can write it as plus is equal to and it will give us the same value as the whole program it will give us the value three now if I run it again and this will become four so similarly this is for addition for subtraction for division for multiplication for floow division and all those operators that we can use so all right guys so the next in line is the arithmetic operators so the very first one is you know get any operations running thematic operations so the first one is very easy guys we can write 10 addition two numbers and a is equal to 12 and instead of addition we can do subtraction and instead of subtraction we can do division so just look at the difference guys now when I do the floor division we do not have a float value so that is the difference between Division and Flo Division and we can multiply do the multiplication using as risk and if I use double asterisk it will give me the exponentiation of 10 to the^ 2 and yeah these are all the uh maatic operations for now as a beginner the you know aware of after that there are operators like comparison operators which are basically used to compare two values and then we have logical and or and not so these I will discuss when I'm talking about the conditional statements because these two operators are basically used there only if we have to establish a point we are comparing to the program okay so we'll discuss that these two operators there and then we have membership and identity operators also which are used to check if the object is same for identity operator and the membership operators are basically used check if particular data type is actually present in an object or not or the object is present in another object or not that is how it works and bitwise operator is again same we have bitwise and or and not which so talking about the bitwise and operator it basically sets each bit to one if both the bits are one which basically means that if both the bits are true then the answer would be true as well if one of them is false then the answer would be still true if you're using the bitwise or operator and let's say if we have you know one of the bit is one and one of the bit is zero which means one of the bit is true and one of the bit is false then and it will basically change the all all the bits to one only and similarly for not basically inverts all the bits which means if the answer is true it will change to false if the answer is false it will change it true and then we have the zero fill left shift and and signed right shift so in the zero fill left shift the bits are shift left by pushing zeros in from the right and let the leftmost bits fall off and for the signed right shift the shift right is happening by pushing copies of the leftmost bits in from the left and let the rightmost bits fall off basically looks like something like this the left shift and right shift if I want to you know basically do the left shift on 10 by two places the answer would be 40 and if I do the right shift the answer would become two so now that we have also discussed the operators and you know we have established how we work with variables and operators let's move a little ahead and uh talk about various data types that we have in Python all right guys so collections in Python basically are some of the data types that we're going to discuss before that I'm just going to discuss integers and strings for a while so integers are just numbers guys so any uh number number numerical value is you know considered as a number data type or numerical data type could be an integer it could be a float value it could be a Boolean or it could be you know a complex number as well strings are a data type in Python where we store the values with alphabetical you know values and we enclose them in single inverted commas or double inverted commas and uh they're basically the same also if we do not have any distinction between a single inverted comma or a double inverted comma and yes I have shown you like how we can declare a variable guys so this is how I declare a variable let's say yes so this variable is uh I can check the type of the variable this will show me that this is a string v data type and uh similarly if I have another variable which has some uh integer value I can check the type of the variable again and it will show me that it's a integer variable all right so this is all about integer and and strings so the next data type that we have is list in Python which is basically declared in square brackets mutable so a collection in Python is basically you know a container data type namely we have list sets tles and dictionary and they have different characteristics based on how we declare them and how we use them so coming back to list again it is mutable in nature which means you can change them unlike strings so strings are immutable in nature guys so let's say if I have a name equal to a scene so if I want to access some values I can use the indexing guys all right so indexing is nothing but you know the index values that we have over here so I'll just explain what indexing in strings is so basically if I write name and in the square brackets I have written two over here so the index value is two which I want to access and at index number two we have the third alphabet from the string so which means is the indexing order is starting from zero and going under the end of the string so this is how we use strings so if I want to reassign the value at index number two if I write instead of s I want to write a capital S so it says type error which is saying that string object does not support item assignment so basically it's immutable in nature but in the case of list I'll show you guys so let's say a is equal to a list you just declare it in square brackets and to access the values inside a list we use indexing again guys so it can also store duplicate values as well so let's say if I have 1 2 3 4 and five and we'll add one again so just to be sure that we have in duplicate values as well so this is how a list is declared in Python guys and if I want to access I can use indexing and I can use slicing in the indexing as well this is how slicing is done in indexing negative indexing as well which can be used to you know get reverse of a list so here what I've done is I've used the negative step and I iterated from the back so that is how you do it so if I say write it from four and minus one we have an unexpected end of right this syntax eror so as you can see guys this is how it's done all right so from index number four we are going until the end of the list but the Step is a negative one so we starting from here 0 1 2 3 4 starting from here going in the opposite direction because because the step over here is negative step that's why we going in the opposite direction and that's how we are getting the values all right so this is all about list guys and list also comes with a lot of methods that you can use so basically these are the methods that we can use for a list which are reverse remove pop insert index extend count clear copy Etc so if you want to know more about these methods how we can use them we have a full tutorial on list in Python that you can use so I'll just show you how you can insert a value inside a list so let's just check so index number zero we have added the value one so this is how you insert a value and if I use the pop method I am actually removing that particular value from the end of the list all right so this is all about list now coming back to dictionaries guys so let's say we take dictionary and we declare it in FL braces and so we use the FLW brackets here and uh we have to use key value pirs so let's say one is the key this is value two is the key and we'll get another value so these are two value pairs key value pairs and when I print my dictionary I have somewhat like this so if I access one we can use the get method to get the values from the dictionary so if I want to get the value which has the key one I can use the method get similarly for all the keys I can use this or simply I can get the value using indexes as well so in the indexes instead of you know indexes I'm just using the keys and similarly it also has a lot of methods that you can use which is clear copy from keys get which I just shown you items Keys pop and pop item right so this is all about dictionary that we're going to discuss and after that I want to discuss a tle guys so a tle is ordered and immutable in nature which means you also cannot uh you know change the values inside dle and declare a dle again you use round brackets so let's say I give it some values right so I use the indexing to access the values and if I want to reassign some value I have a type error which says tle object does not support item assignment which is same as a string guys so if you want to say save something in a data type that you don't want to change the future you can use a tle guys and it's ordered so you can access the values again and uh one more thing so if I let's say give it some duplicate values it is allowing the duplicate values as well so this is all about tles again and it also comes with a few methods that is count and index so basically I can count the number of values that one has so one has occurred Trice over here and I can check for two similarly I can get the index value for let's say one I'm checking it's giving the index value as zero but it also has a value at index that is second last index and the last index as well but it will just fetch me the value which is you know which occurs the very first time for the method so since it's in the beginning it's giving me this value let's say if I write two over here and um if I check two I'm still going to get the value one so if I remove two from here I'll get the value index as five so I hope you understand this after this we have one more data type that is a set data type guys so set is unordered guys so let's say if I have values 1 2 3 4 5 6 and 7 print over here so we have declared a set using the flow braces and uh it is ordered and so we cannot just uh you know access values from the set using index all right so but we can have all these you know methods that comes with the set data type which is basically you know implement the set operations that you must have heard about or learned when you must have learned about you know when you were learning U set theory so it's basically you know it gets subset superet or okay so we will have one more set and now we will do a union guys so let's see if it works all right so let's change a few values here nine and 10 We'll add so we have just done a set operation do the union of two sets available to us so that is how we can use the you know these data types and these are the basic data types that we have in Python now after this I want to talk about a few Advanced data structures also that we have in Python so these are general you know Python's general purpose built in container data types and you all know python always has something little extra to offer it uh comes with a python module named Collections and which has specialized data structures so I'll mention a few data structures that we have in collections python but before that we will have to from collections import all whenever you're using an external package or a module this is how you you know import using uh an alas you can use an ASX to import everything from the package or you basically import specific specific modules that you only want for your project so so I'm just going to import deck right so we have deck default dictionary there is name tle we have chain map we have counter there is User Dictionary user list and user string so these are the collection Advanced data structures so I'll just briefly tell you about what exactly are these data types and what they do so talking about name tle it returns tle with a name entry which means there will be a name assigned to each value in the Tuple overcomes the problem of accessing the elements using the index values and with name tle it becomes easier to access these values again and since you do not have to remember the index values to get a specific element now see basically what happened here is with data di whatever problems that we had in the you know basic data types Advanced data structures are actually solving those problems so if you take a look at the tle when I discussed you know there was only two methods one was to you know get the index of the number and second was to count name tble is basically assigning a name to a tuple so that you understand or you basically remember the value that you have fetch from the tle then again we have deck which is pronounced as Dex even if it's written as D qu e is basically an optimized list to perform insertion and deletion easily so it comes with a bunch of methods that we can use or we can also use deck to implement stacks and cues in Python which is basically you know way to implement a link list in Python so we'll be talking about that in a while after that we have chain map so it is a dictionary like class which is able to make a single view of multiple mappings so what happens here is it basically returns a list of several other dictionaries suppose you have two dictionaries with several key value Pairs and in this case chain map will make a single list with both the dictionaries in it so that is how you can use chain map then there's a counter guys which is basically a dictionary sub class and uh we can use it to count hashable objects now you must be wondering what exactly hashable objects so hashable objects are nothing but in Python any immutable object you know such as integer it could be Boolean string or tupple is hashable so basically whatever value that is immutable is actually hashable object so counter is also you know basically a subass which is used to count hashable objects and then we have the order dictionary so it is basically a dictionary subass which remembers the order in which the entries were added basically even if you change the value of the key the position will not be changed because of the order in which it was inserted in the dictionary so this is a very good uh Advanced data structure guys which is an order dictionary and uh basically you can remember or it keeps track of which value came first even if you have changed the value of the key so that is one advantage over there then we have the default dictionary guys so which is basically a dictionary subclass that calls a factory function to supply missing values so in general it ises not not throw any errors when a missing key value is called in a dictionary and after that we have user dictionary which is basically you know a class that acts as a wrapper around dictionary objects so the need for this class came from the necessity to subass directly from a dictionary and it becomes easier to work with this class as the underlying dictionary becomes an attribute after that we have user list so this is basically acting like a wrapper around list objects and is a useful Base Class for other list like classes which can inherit from them and override the existing methods or even add a fewer ones as well so now even if I have discussed these Advanced data structures as a beginner you should only stick to a few of them and basically focus on the inbuilt data structures first of all the the basic ones like list dictionary and couple set integers strings and I forgot to tell you about the range right so let's take a look at the implementation of deck as well because uh it basically provides a lot of methods that can be used to implement link list in Python that's why I want to discuss this all right guys so what we can do here is so first of all let's create a list guys and we'll call it as stack because we're going to implement stack over here so one 2 3 four and five and now if I have a tech over here let's call it as stack again and we are going to use deck inside this we'll pass stack and now we have the de so what we have to do here is now we'll use this um stack and let's see what methods do we have so we have upend upend left there is extend left again that we do not really need and we have pop and pop left so these are two methods that we actually need because let's say if I want to remove something from the beginning of the list what I will do is I will write pop so it is popping five which is at the end of the list now if I want to remove something thing from the beginning of the list I can use pop left and again I can use append and append left right so if I want to append I will write one and my stack would look somewhat like this all right so it's actually adding a particular value at the end of the list right so I'll just change it to five because we had five in the beginning and then again if I want to add something in the beginning I will write upend left and one over here now my stag becomes the same and I can remove one let's say now the stack looks like this I will remove one again now the stack looks like this stack dot append five and stack dot append left all right so we'll remove five again now so how will we get the implementation of a stack or a q guys so this is quite interesting so for a stack we have to follow the principle of last in first out so whichever a value is inserted last in the list has to come out first so that is implementation of a stack and um to implement a stack using deck what we have to do is we have to remove the element that was entered last in the list so let's say if we have an empty list and if we use a loop which we'll discuss later on in sessions so we keep inserting the values inside the list or the deck and after a point there will come a point where we have reached the end of the list and the last element has entered so now comes the part where we have to get the last element out so in this case the first value is one so this will come out last from the deck and this is the last element sir so we have to use append in order to get the value and we can put the whole logic inside a loop so that it goes forward imitating the order of a stack so it's a very simple example guys and after that now comes the necessity to introduce functions to you guys because the functions in a python are a classic example of reusability guys how to serve a wide range of applications from let's say GUI and mathematical Computing to web development and testing Python's interpreted already comes equipped with numerous functions that are always available for use which we discussed in the python standard Library guys and uh you could also bring in other libraries or modules to your program and uh you know that basically contain predefined functions and uh you know they're ready to use you'll just really have to do is download download required packages or according to their documentation and freely Avail its useful functionalities by importing them over to your code like I have done over here which Ive imported uh collections module from there I'm just using deck it's basically a function from this module that I have you know imported what I can do either way is uh Define a function guys so how do you actually declare a function so that is the important part here how do we declare a function in Python so you have to use qy word here which is DF and after that you have to write the function name so let's go with function name so I'll pass so this is my function guys I have created a function instead of pass because we have not discussed the control statements I will write return none so this is how I've created a function guys so let's say if I want to print something I want to print hello world so now when I call my function which is function name I'm getting the value as hello world and uh now let's give it a parameter as well okay now when I call it I will have a type error which says function name is missing one required positional argument so what we can do here is add a over here and this is how I've just used a parameter there's a very basic example of how you can use a function in Python the advantage is simple guys so let's say I want to calculate something right so I have two numbers which I will take the input from the user I'll show you that as well and I want to calculate sum of those two numbers very simple example even though we have a predefined method for that we will create custom method for our own usage so the first thing that I will do is I will use a return statement which will return the addition of these two parameters that we will get from the function call all right so now what I'll do here is I will get the input so we'll use X and Y so input is one method that can be used to get the value from the user during run time we're taking int as input because uh we want sumission so so we do not really want integer there and that's why we are doing that and after that we will call our function and pass X and Y over here so let's see what the output is so the first number is 10 the second number I say is 20 and I have a type error guys which says function name takes one positional argument but two are given so I think we have made a mistakes so should be working now so we have the summation of number using functions so this is the very basic example how we can Define function and use functions and uh there's one more function you know concept that I want to discuss which is Lambda function guys so we will take the keyword Lambda and we will pass the arguments and after that we will have the expression all right so let's call it as function now to call the function I provide the values again 10 and 12 and gives me the sum which is 22 so this is the example of using a Lambda function guys which where you can just simply Define the expression and you know the parameters then and there inside the definition as well all right so this is all about functions that I wanted to discuss now we are going to talk about the conditional statements guys so when I talk about conditional statements we really have if else if and else that I want to discuss so these are the conditional statements and apart from these we are going to discuss the control statements which is break continue and pass and now we are going to discuss the comparison operators as well okay so let's say we have these two numbers X and Y so let's first of all check if x is greater than y we will print greater all right guys so when I execute this we are not getting any output the condition is basically false here because X is not greater than y so if x is less than y we have this particular output and let's go for this so what we will do is we will check for another statement using lsf now if first statement is false it will check the other statement so it will check if x is uh less than y it will basically print smaller and we have the output guys so now I want to change this to is equal to so we have again we do not have any conditions now I will print smaller again everything else is failing we are reaching the last statement which is the penultimate statement which is whatever that we give over there it will print for us so I want to talk about the control statements again so let's say if x is equal to Y and we want to break it's saying that syntax error which is saying break outside Loop so basically what we have to do is we have to use break or the control statement inside a loop so we'll do that while discussing loops and let's just call it as equal so to test it out to check if your you know conditional statements are working or not what you can do is get these values from the user so a we have 10 let's say B we have 15 and we have smaller okay let's just put this inside one single block and run so let's say 12 and six and again let's say 10 and 10 equal so this is how we can use the conditional statements in Python now I want to talk about loops in Python guys all right guys so think of an analogy where your teacher has punished you and told you to write I will not forget my assignment 10,000 times okay that's a bit harsh she has told you to write it 10 times so what you can do is so using python what we can do is make this task very easy for so I'll just explain how we can use a for Loop for the same task so let's say we have to print I will not forget my assignment so we have to print this 10 times or 20 times or any number of times so what I will do here is I'll take a for Loop for I in range okay 11 because we have to print it for 10 times so as you can see guys this is a very practical implementation of how we can use a loop so two things to to actually see here observe here the number of iterations that we want and what exactly is the output that we want from the loop so this is a very simple example so we have used for I in the range which is basically the number of iterations we want all right so for the current iteration it will start from the number zero so range zero then the range will become two the range will become 3 4 5 and when it reaches 11 the execution will stop so this is how for Loop works we give it a statement we give it an ending already know the execution will end at this particular iteration and we have the output and in this particular section or the block we can have any code that we want we can have a function here we can have a class we can have any code that we want to iterate over and over again so that is how Loops in Python work now we have another kind of loop which says we have a statement and as long as is it true it will keep on going and going so for the same task what I can do here is get a count variable and as soon as count is equal to 10 or 11 let's say and uh we'll have count is equal to 1 or zero and we will print I will not forget my assignment and after that we have to increment the value because that's how we will increment the value again right so I actually uh you know forgot to mention here here the condition has to be true all the time so as soon as it becomes greater than or equal to 11 it will stop the iteration so we have our task performed here exactly as we wanted to so these are the two Loops that we have so the only difference between for Loop and a y Loop is in while loop you have to give the statement and the loop will run on until or unless the statement becomes false so you have to keep in mind that you are actually incrementing the value or you know you're providing some sort of closure to the loop so that the condition will become false eventually otherwise the loop will run on forever and for the fall Loop we already know how many executions will happen so that is the difference the main difference between while and for Loop so now we'll talk about the iterators guys so a python iterator is a container containing a countable number of values and a value in a container can be traversed using iterators which is particularly list guys and apart from traversal iterator also gives access to data elements in a container with but does not itself perform iteration which is not without some significant Liberty taken with that concept or with trival use of terminology an iterator is almost similar to a database cursor in Behavior so let's see how database you know this actually works the iterators and after that we will talk about python it tools guys so let's say we have a list right so it has some values 1 2 3 4 5 6 7 8 9 and 10 so now iterable is exactly an object which one can iterate over so right now a list which we have declared over here is an iterable an iterator will be an object which is used to iterate over the iterable object using iter and next method now to make this list iterator what we have to do here is okay I'll write a is equal to it to a now this is an iterable object guys what I can do here is using this iterable object I can use the next method and get the value right so using this next method we can get the values or iterate over this iterable object so every time I execute this next I'm getting the next value and I when I reach the end value of the iterator it will stop the iteration or it will throw an error because we have not specified the stop iteration over here so it's yes the stop iteration is there and uh so that is exactly how we use iterators in Python basically we have iterables which we can convert to an iterable object using iter method over here or we can use it tools which I will discuss now so what exactly is python it tools it tools is a module that has a lot of functions and tools that can be used to create iterators in Python so there are a few methods that it tools comes with and uh let's just talk about how they work so the tools are the method that can be divided into subcategories so there are infinite iterators and then there are the iterators that will terminate on the shortest input sequence there are combinatoric iterator as well so let's just talk about the infinite iterators first so we have three tools for infinite iterators using it tools so first of all let just import we will import count so count basically has two parameters start and a step and the iterator will return evenly spaced value starting from the start so let's see how this works let's say a is equal to count we have two parameters which is start and a step let's say starting from zero give it a step 10 all right so now each time I use the next method I'm getting the values so basically what I'm doing is I am getting these you know iterators from these methods basically this is an iterable object which I can iterate over using next or I can put it inside a for Loop since it's an infinite iterator if I do not give it stop iteration condition it will just go on forever and similarly infinite iterator we have count we have cycle and we have repeat cycle basically returns a copy of the elements from the iterable and takes only the iterable as the parameter then repeat basically Returns the element again and again so the repetitions are determined according to the parameter that decides the number of times the object will get repeated and to check the exact syntax we can go to python it tools you know the official documentation so here we have all these uh you know how you can use the infinite iterators you know iterators terminating on the shortest input sequence there is accumulate chain Dot from iterable compress so all these iterators they have also given the examples so you can use accumulate so let's say you have itable over here it will give the values again like that so this is how you can use the it tools methods and then again we have combinator cators which will give the product the permutations combinations and combination with replacements so this is a very important you know module that we have in uh python which is inbuilt guys it's basically giving us these uh iterable objects which we can just use wherever we want where wherever you want to iterate over an iterable we can use these objects this is why it is important concept that I wanted to discuss so as you move forward when you learn how you can work with loops and then moving forward you will come across complex questions and for the very similar reason I discussed the advanced data structures also so because as a beginner there are a few things that uh you will get spoonfed and some things you will have to you know eventually discover so I I didn't want to you know keep you into dark because Advanced data structures are something that you will eventually use working the complex problems so similarly for the it tools also you will have to use these iterators some way or the other in complex problems that is why we're discussing this and after that we have generators in Python guys which is also a very interesting topic so generators are basically functions that return traversable objects or items all right so how is it different from a iterator we'll discuss that so these functions do not produce all the items at once rather they produce them one at a time and only when required all right so whenever the for statement is included to iterate over a set of items a generator function is run and generators have a number of advantages as well so we'll discuss these advantages first so without generators in Python producing iterables is extremely difficult and lengthy and generators are easy to implement as they automatically Implement iter and next so in order to create an iterator we have to use iter and next but uh using generators we can just Implement them automatically and stop iteration also is implemented automatically which we have to you know use otherwise and memory is saved as the items are produced as when required so whenever you're requiring that then only the items are use so it's actually saving a lot of memory as well and this fact becomes very important when you need to create a huge number of iterators and this is also considered as the biggest advantage of generators it can be used to produce an infinite number of items as well and they can be used to pipeline a number of operations so these are all the advantages of using generators now the question here is what exactly is a generator so we have talked a lot about generators what are the advantages we know that it's actually returning traversable objects or items so generators in pythons are created just like how you create normal functions using the definition that thef keyword and uh the generator functions make use of the yield keyword instead of return so that is the only difference between a normal function and a generator function and this is done to notify The Interpreter that this is an iterator so when you're using yield The Interpreter already knows that this is an iterator and not just this generator functions are run when the next function is called and not by the name as in case of the normal functions so you can just call next and the generator function L RW so we'll take a look at you know a little implementation of how generators Works in Python so let's take it up to jupyter notebook and we will see how generator Works in Python guys how we Define a generator function so we are going to use the keyword definition let's say let's call it as generator because this is going to be our generator function and after this let's take number A isal to 1 or let's take this 10 after this I will yield this number a so when I call next on this I'm getting type error which is function object is not an iterator so I have to create an object so this is my object now and if I write it like this I'm getting is 10 and the iteration is stopping because this is not exactly an iterable so let's take it in the range 10 so we'll have 1 next is 0 10 okay so we basically forgot to convert it into an iterable now it should work fine so if we take one element all right so we'll Define something so that we only get uh one value at a time a of Z and then a of 0 is equal to this so let's call it as B and now we will yield B you know just defining the logic all right all right so instead of this what we can do here is let's just take a number first all right guys so this is just to show you how you know you can define a generator function and this is a very basic generator function that we can use so right now we already done with iterators and generators and we're left with decorators but before discussing decorators let me just discuss a concept which is class and objects so as you already know guys if you are from a programming background so a class is nothing but you know a collection of uh a lot of variables objects functions basically a lot of things and that you can wrap inside a class and use it for later or you know you can inherit from those methods or something like that and you have objects to take values from them so now to fully understand this let's consider an analogy so let's say you have a class and your class is basically your complete College your Institution is the class and you have different variables there so for each branch of the University or the college is a member function and whenever you want to call let's say School of Engineering or School of Architecture you have separate member functions and all of that is enclosed inside a class which is the University and inside those member functions there are variables which is basically you know the number of students and the details of those students so what you can do here is create an object and to pinpoint exactly to the particular student that you want from the School of Engineering what you will do is you will call the method the memo function which is containing the values of all the people from the School of Engineering branch and then find the particular details using that particular member function without disrupting others so this is how the analogy works and this is a very basic example also I'll just show you how you can create a class let's say we create a class like this and we have a function let's call it as School of Engineering so let's call it as s soe and it has some values and it returns. name is equal to name and uh we'll write branch is equal to this thing all right so we'll call it as engineering and we will return name and Branch so let's see if it works so now let's create an object to create an object what we have to do is we'll just create an object call uni Now using this we call the memo function provide the name let's call it as this and we are getting these values so now what happened here is I had a class University using the parameter I'm providing this name particularly but with that name I can add values guys so let's say if name is equal to we write computer science engineering else we will right branch is equal to uh let's call it as mechanical just to show you guys this is a simple example so now let's say this is an example so we have computer science engineering now let's say I write it as somewhat like this let say I write home car okay we have an unbow local variable Branch reference before assignment so I'll just uh remove this I think this is the arrow right so now I think it's be fine all right so what I've done here is even if I remove this now because I was making a syntax error slide syntax error so I'm getting this value guys so this is how we can use classes and object you know easily in uh Python and after this I want to discuss uh decorators in Python and before that this is just a very basic explanation of how classes and object is used what I want you to do on your own is after you you know after you're familiar with classes and objects I want you to do it as an assignment to look into how inheritance works how the objectoriented concepts work and how you can Implement multiple inheritance and all these Concepts so we already have tutorials on our YouTube channel that can help you but as a beginner I want you to try it on your own to implement you know using basic implementation of all these Concepts that I'm talking about so moving on let's talk about decorators so decorators in Python are very powerful which modify the behavior of a function without modifying it permanently which means is basically wraps the function and since both the functions are callable it returns a callable so in hindsight a decorator wraps a function and modifies Its Behavior let's take a look at the example to understand this better as I've already told you a decorator will wrap another function and uh modify Its Behavior so we will understand this with a basic example guys so we'll take a function first of all and uh using this function we going to pass the function fun as the argument and uh okay let's call it as Function One this will be the argument that we are passing function as an argument guys you heard me correctly guys you can also pass a function as argument now we will have another wrapper function and inside this we will have a statement let's call it as hello and after this we have a function that we have passed as an argument and after this let's print something else right so we'll write welcome TOA and we will return rapper so now we'll have another function function two which we will pass as argument in our function one and let's just keep it simple print uh learner here now we will call the function one all right so now we'll call the functions or make the function call so function 2 is equal to call the function one pass function two over there and call function to now as you can see guys we have basically used a decorator so this is a simple implementation of how we can you know modify the behavior of the function and U instead of doing this what we can do here is uh write this and uh we will remove this all right guys I think we're making mistake here so function has to be there and now we're getting the same output but instead of making that call over there we just writing it with an add symbol and uh that's how we use the decorators in Python and uh now we will move on to python standard Library guys so this is the official documentation of where you can find the python standard library but what exactly is there in the python standard libraryies the built-in functions and the buil-in types or you know the built-in exceptions all these values that we have so we have date time there is calendar collections all right so we so we basically use the collections module which comes from the standard python Library so it is a very important concept that we have in Python where we can just learn about all these inbuilt data types first of all or inbuilt functionalities that comes with it there is it tools there is fun tools as well which is basically a higher order functions and operations on callable objects so this is also one of the very important concept that we have in Python also so there is CSV and all the file formats are there so python standard Library plays a very important role when you're learning Python and I will suggest you to explore all these values that we have all these functionalities that we have in Python standard Library so we have built-in functions so let's take a look at the buil-in functions that we have there is ABS the all asai there is list all all these Constructors checking the length or and in the documentation they have given how it works as well so as a beginner I would suggest you to check out the python standard Library it will help broaden your perspective about what exactly is possible with python so that's why I wanted to discuss python standard Library and uh not just the buil-in functions let's take a look at built-in types as well so there are truth value testing and uh comparisons and Etc these are something that uh you know if you read about them in documentation you will understand and there is text processing Services as well string the regular expression text WP uni code data and all these things read line is one of the things that we are going to use while doing file handling get to that now that we done with the standard Library also let's talk about the exception handling guys so what exactly is exception handling so in Python the try and accept block is used to catch and handle exceptions basically what happens is when you are executing a program there are errors and there are exceptions so exceptions usually happen you know during runtime and you have to take care of unless repeat or they will you know cause execution problems so python basically executes a code considering the try statement as a normal part where as the accept statement acts as the program's response to any exceptions that may occur and exceptions are convenient for handling errors and special conditions in a program so if you're working with a code that can produce an error then you can use exception handling and also you can raise an exception in your own program by the raise exception statement and raising an exception breaks current code execution and Returns the exception back until it is handled so there are a few exception errors so these are different types of error such as IO error which is if the file cannot be open you will have an input output error when an unrequired key is pressed by the user there is value error when the built-in function receives a wrong argument there is end of file error which is hit without reading any data and there's import error if it is unable to find the module so let's do one thing guys okay so let's say if we have not installed a module in Python so we will basically have an import error all right so I'm going to use so let's do this CV2 do read and we have a name Arrow which is saying CV2 is not defined right so let's take a look at try print XYZ and catch block try and except print exception all right so now I will try to import something that I have not really installed here so we'll do all right so we already have Pi audio so we'll try to import something that we do not have so let's do this and it's calling the exception so as long as whatever code that you have over here okay we'll remove the whole triy block and except block so we getting the output as exception which is in the accept block because it's not able to import P Doge we basically getting an error that's why it's you know going to the accept block that is how exception handling is done in Python guys so wherever you can find any errors in your program that you want to handle you can just put it inside a try and accept block and whichever code that you want to execute will be executed in the tri block or if at all you come across any exceptions or errors it will be handled by the except block so that is all about exception handling next up is multi-threading eyes so a thread is basically an independent flow of execution a single process can consist of multiple threads and each thread in a program performs a particular task for example when you're playing a game of let's say when you're playing FIFA on your PlayStation and uh the game as a whole is a single process but it consists of several threads responsible for playing the music there'll be a thread for playing taking the input from the user there'll be a thread running the opponent synchronously there'll be a thread and all these threads are separate and responsible for carrying out these different tasks in the same program at the same time every process has one thread that is always running that will be the main thread which will make sure that the game is running of course and this main thread actually creates the child thread objects and these child thread object is also initiated by the main thread only so when you open the game which is the main thread these all child threads are also initiated and they're running simultaneously but there is a main thread that is making sure that each of these thread is running as well and let's take a look at when we actually use multi-threading in Python before moving on with an example so multi-threading is very useful for SA time and improving performance but it cannot be applied everywhere and in the previous FIFA example as well the music thread is independent of the thread that takes your input and the thread that takes your input is independent of the thread that runs your opponent so these are all independent threads and uh they run independently because they're not interdependent so therefore multi- threading can be used only when the dependency between individual threads does not exist so how do we achieve multi-thread in in Python multi- threading in Python can be achieved by importing the threading module first of all so you have to import threading module so let's see if we already have threading so we're going to import everything from threading now the next thing that we have to do is we will perform multi-threading which we can accomplish without creating a class as well so we have you know created or imported everything from threading so now we are going to print current thread do name so we'll get the name of the current thread which is the main thread and uh now after that we will create a main thread function let's call it as function and inside this we will have all the child functions right so we will have let's say this is a child thread and uh let's call child is equal to thread and uh we'll get Target is equal to function and uh yes and we will start the thread now we will print Cur print thread dot get name again let's see okay function attribute has no name okay so we are still getting main thread okay let's see what we are doing wrong actually we have to keep it outside the function and uh let's print something here all right so in this output we have the current thread which is main thread after that it creates a child thread and it runs and whatever we can run it inside this thread basically and after after that we have the current thread again which is the main thread so this is how we implement or achieve multi- threading in Python this is a very basic example how you can do it and this is by not creating a class so this is a very basic example also we have a tutorial on Multi thre that you can f for where we have other implementation methods as well that you can follow so what we can do here is we can do the multi-threading by extending the thread class as well and after that we can do one thing also we can extend the we can do this without extending the thread class as well basically advantages of using threading is it has a better utilization of resource it simplifies the code allows um concurrent and parallel occurrence of various task and reduces the time consumption or response time thereby increasing the performance as well so this is all about multi-threading in Python now let's talk about importance of file handling in Python so the question must have stuck your head isn't it why is so buzz and stress about this simple thing well for that let's take an example suppose you want your python script to fetch data from the internet and then process the data now if the data is small then the processing can be done every time you run the script but in case of a humongous data repetitive processing cannot be performed hence the data process that needs to be stored this is where the data storage of writing to a file comes in and one thing to note while writing data to a file is that it's consistency and integrity should be maintained so that is why file handling is it's quite important Concept in Python Programming and as a beginner it's easy to learn this you know mastering the basic concepts so that you'll be able to understand this in a better way and don't have to come back to it later on so once you have stored your data on a file most important thing is its retrieval also because in computer it's stored as bits of ones and zeros and if it's retrieval is not done properly then it becomes completely useless and uh data is set to be corrupted so writing as well as reading is also important aspect of file handling in Python and uh now we're going to learn about how we can open a file or you know appending or writing to a file and closing a file all right guys so now what we'll do here is uh we will open a file using file handling operations write something in a file and then we'll try a pending a few values there and then we'll close the file so I'm going to take this uh okay just create an object here let's call it new file using open I will give the file name uh let's say this is my new file. dxt and after that I have to give the mode here which I am going to give it as x and t all right so we have created a new file now what will happen here is we will write something to the new file and let's just write this is a new file right and now we will read from the file all right so we'll do one thing before we can read it again let's close it and now we'll create another object and we will call it as read file and using this open again we will read the new file and now the mode will be RT as you can see guys using this readline method we have just read the file that we had just created so let's close it and after this we will create another object call it as right file is equal to open then open the new file again and now we will write into this file so we will write w so if I want to write the complete file I will use WT and if I want to append something I will use at right yes now I will use right guys so we will write again okay and now we will close the operation now again we will use another object and using this we will read from the file new file.txt and we are going to read right so R new file dot now since there are too many lines there you're going to get all the lines and so this is a new new file and I'm pending this in the file also if I instead of uh using at here if I had written WT this will be the new line rewriting the whole content of the file so this is all about file operations guys a simple basic operation of how you can open a file create a new file read from the file open new values write new values there and ultimately you can close the operation again we're good to go now we are reaching the end of the uh SE guys so I'm just going to you know tell you about a couple of programs that you can you know write after mastering these Concepts so I would suggest you to check out our python projects tutorial and we have uploaded 10 projects there starting from the beginners perspective there are inmediate projects as well and advanced projects as well so you can check it out also we have a python programs blog and there's a lot of content that you can find online on our YouTube channel so I'll just show you two programs guys P androme Checker and the second program will be a simple basic guessing game so in the first program we're going to make a function guys right so okay this could be anything and uh so first of all what we'll do is uh there'll be a new number which is equal to number and we revers the whole thing because since we can use uh indexing with strings as well so it doesn't matter if it's a number or if it's a string we can just um you know change the values there so I hope everybody knows what exactly is a palindrome so a palindrome is a number or a string which is same if we reverse it I mean the spelling would be same like Madam if you reverse it it will still be spelled like m a d a m right so now what we want is we want certain conditions here so if number is equal to new we know that it's palindrome so we'll print palindrome and else if number is not equal to new we know that it's not a palum and in any case if we do not have any values we'll print enter again right so now we call our function here which is uh palindrome let's give it a palindrome first of all let's just to check it's a palindrome guys so if I change it to let's say Eda not a palindrome and uh now let's switch it to a number here so int object is not subscriptable so what we can do here is uh we can probably change it to a string and uh let's see if it works yes it's a palindrome and uh let's check for another number oh no it's not then again let's try it for this number it's palr so basically we have just made a function to check if a number is a palr or not similarly you can do that for you know calculating the factorial of a number there you will be making use of Loops in Python and and other Concepts like conditional statements that we have used over here now the next program that I'm going to show you is the guessing game so basically we going to import random over here all right so okay we'll just take a number which we're going to guess so Random dot random range we'll take the range from 0 to 100 let's take the step two so we'll have only 50 values that we can calculate now we take a value from the user right so we take input and and uh enter number all right so basically what our aim here is right this is invalid syntax our aim here is whatever the random generator is generating over here we have to guess that correctly so whatever value that I enter over here I have to check if that is equal to number or not so what I'll do is if number is equal to guess we'll print U when else we will print keep trying okay right so it's saying keep trying because uh it's a number that we did not really guess correctly so I'll put this over here all right so let's generate a number new number again okay we'll remove this now we run this now I'm entering a number let's say enter 50 says keep trying and now let's get number also it's 70 so let's say if I enter 70 over here it says you win so now a game has to be you know in in a fun way so we'll add condition here and we'll run a loop so while we say so we can give as many conditions here like we can give condition until you guess the number you can keep on going guessing or you can do one thing or while count is less than let's say five or less than six we will keep running this program right guys yes and uh after this we will do a count plus is equal to 1 so each time we go to the else block the count value will be increasing and uh let's give count a number here let's give it a zero now run it again so we know that the number is 70 already we just check it for the program so let's say we get 10 okay it says keep trying we give 20 it says keep trying let's give 30 it says keep trying 40 keep trying so we have four values now the count would have become 1 2 3 and this is four this is five and yes so we have got out of the loop because the count value became six and if you give it the value that it needs you win so even if you win the program still keeps executing the numbers right again and again until the count reaches six it exactly does not have any other value right so we have made a mistake over here so what we want to do here is let's keep the count out of the if block right and uh after this if we win we want to give a break right right so we R again okay we'll have to restart the kernel to you know bring it to live because we did not stop the program over there so restarting the kernel now right so if you guys do not really know how Jupiter notebook also works so it's part of anaconda python so you can download Anaconda python from the official website and if you want any assistance there we have anond tutorial as well which you can follow right so if we have 70 let's say okay the number is not defined so we'll have over here so our random number right now all right so we'll have to probably execute this as well so random number is 12 now so we want to check if we guess it correctly is it okay so and the execution stops so this is how you create simple programs but before we move on I have another question for you guys and the question is which of the following is a valid python variable name and the options are option A two variable option b underscore variable option C variable hyphen name and option D variable space name please comment the right answer in the comment section below now that you have got an idea of Python Programming we will move on to the comments in Python here you will learn how to document your code which is crucial for making it easier to read and maintain what are comments no they are not something there just to increase the size of your code but guys they are indeed very meaningful comments are programmer coherent statements that describe what a block of code means and they get very useful especially when you're writing large blocks of code say for example you've developed some software previously and now you're working on something that's new and completely different at this point of time you find that your previous software is throwing some error you would have completely forgotten what you did and how so this is where commments come into picture a good code actually consists of relevant comments these commments actually increase the readability of the program not just to the programmer but to the others as well now let's move on towards a Jupiter notebook and write some comments All I'm going to do over here is I'll open a new python notebook and I will rename this notebook to rename your notebook guys all you have to do is click on the title give whatever title you want and use rename like I've told you before comment start with a hash character in Python so here I'm going to write a comment preceded by a hash as you can see my output there is nothing related to the comment line and whatever I have printed in the print statement has been returned as my output now this is how comments work they do not show up in your output now let's get back to our presentation and see how they are interpreted which is exactly what is our next topic whenever The Interpreter encounters a hash symbol it omits whatever is present after that the hash character actually tells the interpret to stop reading whatever is present after that until the end of that line so when you're writing commence whatever is present after your hash character is going to be omitted by your interpreter now what if the hash character was present inside a string let's go to our Jupiter notebook and see what happens I'm including a hash character within a string and I will run this as you can see when I run this the string is returned which means a hash inside a string means a hash itself and nothing else so you cannot write comments within a string okay so I hope you've understood how to write comments now let us move ahead and see what are the types of comments comments can either be single line or multi-line single line commands can either appear individually or in line with some other code multi-line commments have to be preceded by a hash character in every line they appear now let's see a small example of single line comments like I've told you before single line commments can appear either in an individual line or in line with some other code now let's move on towards a Jupiter notebook and write some single line comments I'll just create a heading over here to create a heading all you have to do is go to code select heading give whatever heading you want as your heading and prefix it by a hash a single hash tells that it's H1 level heading two hashes tell that it's H2 and so on you can use the heading level of your choice here I prefixed my Heading by a single hash which means it's of level H1 now let's write some single line comments as you can see over here my first line of code is a comment line I've prefixed this line by a hash character and in my last line I have an inline comment this inline comment is present with some part of the code as you can see in the output none of the comments have been returned now let's get back to our presentation and see how multi-line comments work like I've already told you multi-line comments can appear anywhere in your code but each line needs to be prefixed by a hash character for example as you can see on your screens I have a hash character present in the first two lines of my code after that I have some code followed by it you can see in the output that none of these lines have been returned now let's go to our Jupiter notebook and write some multi-line comments as you can see over here I have three initial comment lines and all three have been prefixed by a hash after that I have some code and you can see in the output that none of the comment lines have been returned and whatever code is present after that an output is returned based on this code now typing a hash everywhere might be a problem and many of us would not like to do so let's look at some Shortcut methods of how to comment multip lines at once all you have to do is type your multi-line commments first hold the control key and left click wherever you want to insert a hash character just like how I'm showing youall and then type it once and it appears wherever I have inserted the cursor as you can see on the screens now in case you want to remove multiple hash hash characters all at once do the same thing hold the control key click on wherever you want to remove the hash character from and press the backspace key as you can see from two lines I removed hash character in a single go so these are some Shortcut methods to comment multiple lines many of us think that commments and Doc strings are same now let's move ahead and see what are doc strings and whether they are actually comments or not doc strings are not actually comments but they are documented ation strings these strings are written within triple codes they are not assigned to any variable and many of times they are used as comments as well now you'd be thinking what is the difference between doc strings and comments doc strings are not omitted by The Interpreter unlike comments comments are omitted by your interpreter and nothing present after the hash character is going to be read by it on the other hand doc strings are strings that describe something about the code doc strings actually tell what some function is going to do whereas the comments will tell how it is going to do so this is the difference between dock strings and comments now let's go to a jupyter notebook and see their functionality like I've told you before doc strings are written within triple quotes as you can see in the output when I execute this it Returns the string itself whereas in case of a comment when I execute a comment it does not return anything which means The Interpreter does not omit doc strings whereas it omits the command now these dock strings are efficiently used when you want to describe something about a class or a function or something else now these dock strings can either appear in your output or they can be omitted based on where you're going to place them let's try to place a dock string initially before the code starts as you can see in my output the dock string has not been returned whereas when I use the dock string IND ually without any code and I executed it you could see that it had returned the string itself but when I include the doc string before the code and after that I've included some code lines and I run this you can see that only the output for my code is present and nothing related to the doc string has been returned as my output now let's try to include a doc string after some code as you can see over here when I included the doc string after the code it has returned the output for the code as well as the string itself so when you're making use of Doc strings just be specific of whether you want it to be returned in your output or not many of times these strings are called rather than writing it again and again so I hope you've understood what are commands and Doc strings as well here's another question which character is used to start a single L comment in Python options are given on the screen and if you know the right answer please leave it in the comment section below with a good understanding of basic Python Programming let's dive into operators in Python this topic will introduce you to the different operators used for performing operations in Python so let's try to understand what exactly is an operator an operator is used to perform operations between two values or variables now we can call the operator S as constructs or special symbols that are used to manipulate the values of the operant now you must be wondering what is an operant so the value that we use in an operation are known as operant these operant can be variables or any data type that we have in Python so let's take an example here so we have two operant operant 1 and operant two now when I add an operator between them we can get the result according to the type of operator that we are using here so before moving on to the types of operator at that we have in Python let's briefly discuss variables and data types in Python the purpose of discussing variables and data types is to get an idea of what exactly is variable and data types because while explaining the different types of operators we are going to use these variables and data types as well so variables are nothing but the memory locations where we store a value and these values we may or may not change in the future according to the properties they possess there are six data types in Python namely numbers string list dictionary tle and ass set now let's take it up to jupyter notebook to understand these data types briefly talking about numbers or numerical data types they mainly hold the numerical values for example a variable let's say x is going to hold the value that is 10 so this is going to be a number or a numerical data type now in numerical data types also we have four types of data types first of all we have integer which is going to hold the four numbers then we have float data type which is used for declaring decimal point values and then we have complex numbers which are used to declare imaginary part values for example we use the J as imaginary part over here and then we have a Boolean data type which is used for categorical output that is true or false so when I print the Boolean number over here it is going to give me the value as true or false so this was all about numbers talking about strings now strings are used to represent represent the characters or alphabets we can use the single or double codes to declare a string in Python also strings are immutable in nature which means you cannot change a string once you have declared and to access a value in a string you can use the index values over here so when I use the index number two it is going to give me the value at the index number two here so this was all about strings guys talking about list list is a sequence which is ordered and changeable which means you can change values in a list to declare a list you have to give a name for your list and we use the square brackets to declare a list in Python list is also index just like a string so we can use the indexes to access the values from a list and we can store different values in a list as well for example I can use numbers over here give duplicate values as well and I can use strings over here as well so when I print my list it is going to give me the value like this now talking about dictionary dictionary is a sequence just like a list but we use the key value pair in a dictionary I'll show you guys to declare a dictionary we use the curly brackets now I'm going to give the key value pairs over here so let's say this is my key one I'll give a semicolon now I'll give the value over here I'll give one more key value let's say key number two so when I print my dictionary over here I'll get the values like this now since it has a key value pair it is not indexed which is why we can use use the unique key values as an index to access the values in a dictionary so what I'm going to do is I'm going to write the index number as my key value and it is going to fetch me the value at that particular key so let's talk about set guys a set is also a sequence which is unordered and not indexed which means you cannot access the values using the index number so I'll just write a few values over here some duplicate values as well so when I PR my set over here it is going to give me the values like I have mentioned over here and it is not going to hold any duplicate values in a set also we use the curly brackets to declare a set now talking about topple tupple is immutable in nature which means you cannot change a value in a topple once you have declared and we use the round brackets to declare a topple in Python so I can give as many values as I want over here even the duplicate values as well so when I print my tle over here I'm going to get these values that I have declared in the tupple so the difference between a tuple and a set is not index and it does not contain any duplicate values but a tle can contain duplicate values and it is index as well so we can declare duplicate values in topples but not in the set so this was a brief discussion about variables and data types guys if you want a detailed discussion about variables and data types you can check a video on urea platform where we have discussed variables and data types in detail where we have also discussed various operations that you can perform on a data type moving on to the different types of operators that we have in Python so here is a list of all the operators that we have in Python so first of all we have arithmetic operators then we have assignment operators comparison operators logical operators then we have membership operators identity operators and bitwise operators so we will be discussing all of these operators in detail so let's talk about arithmetic operators arithmetic operators are nothing but the operators that are used to perform arithmetic operations between variables or two values so these are the arithmetic operator symbols that we use in Python so we have addition subtraction multiplication division modulus exponentiation and flow division so let's take it up to Jupiter notebook to understand the concept of arithmetic operators so let's say I have two variables X I'm going to give this value as 10 and then I have one more variable let's say y I'll give it a value let's say 20 now to understand the concept of arithmetic operators what I'm going to do is first of all I'll try to perform addition between these two variables so I'll just write plus over here and when I execute this I'm going to get the addition as my output now to perform subtraction I'm going to use the subtraction operator and it is going to give me the value as the subtraction over here similarly I can perform multiplication then I can also perform exponentiation so I'll use two as tricks instead of one for exponentiation it is that easy in Python guys now we will perform division over here so it is going to give me the value of the division now when I do the floor division I'm going to get the value over here as well one more operator is left that is the modulus so I'll try to perform modulus as well so it is going to give me the value that is the remainder so this was all about arithmetic operators guys so these are are all the symbols that we can use for various purposes like addition subtraction multiplication division Etc I hope you are clear with the concept of athematic operators now let's try to understand the next operator that we have which is assignment operator so you can imagine what an assignment operator is by the name itself that is assignment so we use the assignment operators to assign values to a variable or any value that we have in Python right so we have assignment operators like is equal to then we have Plus is equal to so all these symbols we have let's try to understand what all these are used for for example let's say we have a variable X which has a value 100 now when I write this X+ is equal 10 it is going to mean the same as x = x + 10 similarly we can write xus is equal to multiplication is equal to division is equal to or exponentiation is equal to now let's try to understand these operators or the assignment operators in Jupiter notebook so first of first of all we have is equal to as our first assignment operator so I'll have one let's say I have X so I have not assigned any value to this let's say what happens okay let's try one more variable I'll write this so it is showing me a name error which is saying name a is not defined because I have not assigned a value to it so in Python until you assign a value to a variable it is not going to be declared in Python so now when I give the value to this variable let's say I'll write five over here it is not showing any error which means I have assigned a value to this variable now let's try to understand other assignment operators let's see so what does plus is equal to mean in Python so when I write this what should be the output guys so let's try to understand this so when I print a I get the value as 10 so why I'm getting this value because I have assigned the value five over here then I write one more assignment operator that is plus is equal to 5 so what is going to happen over here is it is going to be same as a is = to a + 5 so we have five over here and we have added five more to this statement which means we are getting the result as 10 over here now let's try to understand other assignment operators as well so let's say exponentiation is equal to 5 so let's see what the output will be so when I print this I'm getting the exponentiation to the value of five since a is equal to 10 and we are doing the exponentiation until five digits so we getting the output as 100,000 so this this was all about assignment operators similarly we can do the division is equal to then we have minus is equal to so these are all the assignment operators that we have in Python now let's talk about the next operator that we have which is comparison operator so comparison operators are nothing but the operators that we are using to compare two values or objects right so we have comparison operators like equal not equal greater than less than greater than or equal to and then we have less than or equal to as well so let's try to take an example over here so when I use the equal operator I'm going to write the statement as just I have written over here x is equal to Y so when I'm using the comparison operator I'm actually using double equal to so this is the basic difference between assignment operator and comparison operator so let's take it up to Jupiter notebook to understand these comparison operators guys so let's say I have two variables value is equal to 10 and number is equal to 20 so to understand the comparison operators let me take one more variable I'll say this will be our Boolean variable so what I'm going to do is I'll write Val is equal to number one what I'm checking is or comparing these two values so what exactly I'm doing is comparing these two variables or values that we have that is Val and number one so when I print this compare variable what I'm going to get is either true or false so it is going to be false because values is not equal to number so I can do the similar thing I can check whether it is greater than or I can check if it is less than so when I write 10 over here so I can similarly check if it is greater than or equal to I can check if it is less than or equal to so these are the comparison operators that we have in Python which we can use to compare two values or two objects now let's try to understand the next operator that we have which is The Logical operators so logical operators are used to combine conditional statements so what are the conditional statements that we have in Python so let's briefly talk about conditional statement guys so mainly we have three conditional statements in Python we have an is if statement then we have an else if statement and we have an L statement so I'll give you an example for better understanding so for these two variables only I'll write if well is equal to number one print equal else if well is greater than number one print greater else print smaller so what happened here is guys first of all the execution will go to F statement it will check this condition if this statement is true it is going to print this value if this is false it is going to move to the next statement that is the else if statement that we have over here it is going to check this condition if it is true it is going to print this statement or if this condition is false it is going to jump to the next statement that is the else statement and I'll give one more condition so if all of these conditions are false it is going to jump to this statement and it is going to print not there over here if all of these conditions are false it is going to jump to the next statement that we are going to have in the program but I have not written any other statements so it is going to end the execution over here only so this is a basic example using the conditional statements now that we are done discussing conditional statements let's talk about logical operators so I have told you logical operators are used to combine conditional statements so what exactly are The Logical operators so we have a logical and we have logical or or we have a logical not as well by looking at the example let's say we have two conditions over here we have X is greater than 5 and then we have X is greater than 10 so let's try to understand these logical operators in Jupiter notebook now let's say I have two statements I'll write X is equal to 10 and what I'm going to do is I'm going to check if x is greater than 10 I'll write and which is my logical and operator and I'll write X is greater than five so what is going to happen if I use the logical and operator if both of these statements are true it is going to give the result as true but if one of these statements is false it is going to give me the value or the output as false so let's see what happens if I execute this statement I'm getting false because one of these statements is false now when I write instead of 10 if I write eight over here let's see what happens since both of these statements are true it is going to give me the output as true now instead of and operator if I use the logical or operator let's see what is going to happen it is showing me that it is true because when we are using the logical R operator only one of these statements has to be true the output will be true but what happens if both of these statements are false it is showing me the value that is false but let's see what happens if both of these statements are true I'm getting true as well so one of the statements has to be true when we using the r operator now talking about logical not operator what I'm going to do is I'll write not in the beginning now I'll specify the condition let's say x is greater than 10 and X is greater than 5 this is the same statement that we have used before and for this we have got the output as false so let's see when we use the logical not operator what is going to be the output I'm getting true as the output here because this statement is negated over here using the not operator and we are getting the opposite value that we should be getting for this statement so this is the purpose which fulfills by using the not operator or The Logical not operator that we have in Python so now that we are done with logical operators as well let's try to understand what are identity operators so identity operators are used to compare objects now you must be wondering what are objects here so everything in Python is actually an object so we can use the data types as objects as well so let's try to understand what are the identity operators in Python so we have is and we have is not so these are the identity operators so what is does is it returns true if both the variables are same object for example let let's try to do this in Jupiter notebook so what I'll do is I'll take let's say a list I'll give it some values let's say 10 20 and 30 I'll take one more list give it the same values let's say 10 20 and 30 and I'll write X is equal to list 1 so when I use the identity operators let's say if I write X is list one let's see what is the output that I'm going to get I'm getting true because X is actually the same object as list one now let's try to write list one is list two even though when we have used the same values in list one and list two let's see what the output will be it is false because these are not the same objects right similarly I can use list one is not list two so here I'm going to get the output as true because list one is not exactly list two even though we have have the same values it is not going to be the same object so this is the concept about the identity operators now let's talk about the next one that we have is membership operators in Python so membership operators are used to check if a sequence is present in an object or not now to understand the difference between an identity and a membership operator okay let's first understand what are the operators in membership operator we have in and then we have not in so it is going to return true if a sequence with the specified value is is present in the object and it will return true if the sequence is not present so let's do this in Jupiter notebook we have already specified these objects so let's try to do if x in list one let's see what happens it is going to show me that it is false because we have no values in X so when I do the same thing with list one in list two now you see we have the same values over here let's see what the output will be it is false again okay let me do one thing now to check a particular value or a particular sequence what I'm going to write is I'll check if 10 in list one so it is going to check if this is going to be present over here or not it is showing me that it is true so what if I write like this 10 20 30 in list 2 it is false so this is the basic difference between is that is then identity operator and membership operators so when I write let's say say it is going to check if this is present in the sequence or not it is showing false because it is not there but what if I add this value over here let's say now when I execute the same statement I'm getting true because this sequence is actually present in the object now to understand the difference between is equal to and the identity operator let's see what is going to happen what if I write list 1 is equal to list 2 it is showing false and have made a change over here so I'll do this once again so when I print this it is showing that it is true but instead of is equal to if I write is over here it is going to show me false because these are two different objects so this is the basic concept of identity and membership operators guys now let's understand bitwise operators so bitwise operators are used to compare binary values or binary numbers so this is a rather difficult concept guys so I'll be telling you about what are binary numbers first and then we'll be moving on to the bitwise operators that we have in Python so these are the bitwise operators like bitwise and bitwise or so these are the symbols used for these operators guys so this is actually what happens when we are using these operators so let's try to understand bitwise and operator first in Jupiter notebook so what I'm going to do is I'll just write 10 and 12 so what is going to happen over here let's say it is showing me the output as 8 but it is not clear why we are getting this output right so let's understand what 10 is in binary numbers so when I write 10 in binary numbers it is going to be 1 0 1 0 and similarly for 12 it is going to be 1 1 0 0 now when I use the logical and operator what it's going to do is if both the bits are one it is going to be one so in this case only first bit is one over here so the output will be 1 0 0 0 and if we convert this to decimal it is going to be the number a so this is the concept between the binary numbers guys similarly I can use 10 or 12 so what is happening here is I have these values let's say 1 0 1 0 for 10 and 1 1 0 0 for 12 now looking at first bits here that is 0 0 it is going to be 1 so all of these bits in the output will be 1 1 1 1 which is exactly is equal to 14 so this is the concept of using the bitwise operators where we are using the values as binary number numbers we are comparing the binary numbers now let's talk about left shift and right shift guys so this is what I write for doing the right shift so 10 in binary numbers is 1 0 1 0 so when I right shift these two bits I'm going to be left with one0 and when I convert this to Binary I'm going to get the value as two so this is the concept of right shift guys now let's try to understand left shift so when I write this I'm going to get the value as 40 now let's try to understand and how I getting this value so 10 if I write it in binary is going to be 1 0 1 0 so when I do the left shift what is going to happen is it is going to shift two values and I'm going to get the value as 1 0 1 0 0 0 so what is happening here if I convert this binary number to decimal I'm going to get the value as 40 so this is why I'm getting the value 40 over here so this is the concept of bitwise operators guys I hope you're clear with the concept of bitwise oper ators it is a bit complicated because we are using the binary numbers even though I'm telling you these binary numbers you need not mention them while using the operators for example for these bitwise operators all these are written over here let's say if you're using the bitwise and operator it will set each bit to one if both bits are one as I've shown you and then for bitwise or operator it is going to be one if one of the bits is one so similarly for exr it will set each bit to one if only one of the bits is one and then we have bit wise not operator which is going to invert all bits let's say if we have all bits that is one it is going to convert all those bits to zero and then I have told you about left shift and right shift as well so this is about operators in Python guys now let's take up a quiz question what is the result of the expression 3 into 3 to the power of 1 and if you know the answer please leave it in the comment section below you have learned about operators now let's explore tupple in Python in this section you will learn how to create and use tupple which are immutable sequences a tupple is an immutable data type in Python and it is almost similar to a list in Python in terms of indexing which means we can access the elements of a tle using indexes and they can also have duplicate members just like a list as well and it is a collection data type that stores python objects separated by commas and let me show you example which will explain how we can create or declare a tle in Python so let's take it up to Jupiter notebook guys as you can see now we are in the jupyter notebook and I have a file named tle in Python over here so I'll just show you how you can declare a tle in Python so I'll just take a variable here and inside this let me get a few values inside round brackets so I'll just go with 1 2 3 4 and 5 because this is a very basic example guys and when I print a over here this is my Tuple guys which is separated by commas and inside the round brackets but there is one more approach to this where you can actually declare a tle like this so you simply have to mention some values separated by commas and when I print a again I'm getting the same value as I was getting before so I can follow both of these approaches to actually declare a tle in Python so this is how we can create a tupple in Python let's take a look at the next topic that we have which is accessing elements in a tupple so accessing items in a topple walk similar to a list and we can access elements in a list using indexes and we can specify the index value and it will return the item that is stored at the particular index value now talking about indexing it is a data structure technique to effectively retrieve the information from a data structure and in Python several data type support indexing like list or string Etc so what happens is let's see for example we have a toule with five natural numbers that have 1 2 3 4 and five so the indexing will start at the value zero where one will be stored and it will go until the end of the topple that is the number five and the index value at number five will be four so in Python we can use the negative indexing as well to access elements in a tle or any other data type that supports indexing so let me take it up to jupyter notebook guys and I'll show you how you can use the index values to access elements in a topple so we have a over here so inside the square brackets I'll just specify the index number let's say four over here because we have five elements so it should ideally you know give me the value number five okay I have an index error which says index out of range because we have only three values over here so I'll be getting to this also like reassigning the values to a topple so I'll just write two now I'm getting the value 30 over here because in my topple that is the variable a we have values 10 20 and 30 so the index number at 10 will be zero so similarly at the element number 30 we'll have the index value as two so we're getting this output now talking about negative indexing so if I write minus one over here what will be the value I should be getting I'm getting the same value as 30 so when we talk about negative indexing it will start with 30 so the negative index minus one will be at 30 and for 20 it will be min-2 and similarly minus 3 so this is all about negative indexing now let me talk about slicing guys so slicing is basically technique in which we use the slicing operator which is colon and it is used to get a range of elements from a tle or any other data type that supports indexing for accessing elements so let me just show you an example this time I want the variable to be distinct and I'll just specify the numbers as let's say okay these numbers from 1 to 9 so when I print this I have a tle which has values ranging from 1 to 9 now talking about slicing it works similar to indexing only it's just that we'll have to add that slicing operator so I'll start at the index number okay zero and then I want to go until the end of the topple so when I print this I'm getting all the values inside the topple so in this tle the ending index is basically eight so I'll just write eight over here and we getting the values until the index number eight so you can see that number n is not included here so when you're are doing a slicing operation the index number that you write after the slicing operator will not be included in the out similarly we can use the negative indexes as well I'm getting the same values and I can use values like these also I'll just write minus 8 the output is the same so this is all about slicing guys now let's take a look at the next topic that we have which is changing a topple so even though topples are immutable in nature but a nested object in a tle can be changed or in general a tle in Python can be reassigned with a different value so I'll just show you the example how we can do that so talking about the python objects let's say I have a tuple which has values 10 20 30 and inside this I have a list as well which has values 40 50 and 60 so this is my topple when I print a my topple looks like this so the first three elements in the topple are 10 20 and 30 and then the fourth element is basically an object which is a list now what I'll do is I'll try to reassign the values inside the topple so I'll go to the third index which is the list and inside the list I want to change the value that is 50 to let's say 55 so I'll just specify one over here and I'll write 55 and now when I print this as you can see I have actually changed the value inside the list guys now let me try to do this with other elements so let's try to change 30 to 35 let's say so I'll specify the index number two let's say I'll write 35 I'm getting a type error which says tle object does not support item assignment so it's basically a way around this error that we will get like the type error if you are trying to change item inside a topple but for these objects the nested python objects you can actually reassign the values very easily now let's take a look at the next topic that we have which is concatenating two tles so it might sound a little overwhelming but joining two tles is a very easy task so you just have to assign the addition of the two tles to another variable and it will return the concatenated tle with values of both tles so let's say you have a tuple with the variable a and then you have another variable B with another topple so what you'll do is you will just assign one more variable let's just say C and inside this you can do the addition of both A and B and you'll get the resultant as has a concatenated topple so I'll take it up to jupyter notebook and I'll show you how you can do this okay we already have a and b so I'll just take one C variable and inside this I'll just do a plus b no errors and I'll try to print C now as you can see I have both A and B inside one topple so I have actually concatenated both the topples inside one topple so this is how concatenation works with topples guys so now let's take a look at the next topic that we have which is deleting a topple so being an immutable data type A tle in Python does not allow any changes and you cannot even remove an element from tupple after the Declaration but there is a keyword which is D and which will delete the whole topple all together so I'll just show you guys so we have a tle c over here which is the concatenated tle so I'll try to delete this I'll just write Del C no errors now when I try to print C over here it's not there because we have deleted the whole top over here so this is how deletion works with a tle guys you cannot delete just one element from a tle instead you can delete the whole tle all together so let's just go to the next topic which is tle methods so there are not many methods like list or you know other data types that we have in Python there are basically a count method and an index method so count basically Returns the count of the items and index will return the index of the item specified so let me show you this with an example so let's just say I have a tle named a and inside this I have values let's just say one one one one I have written five ones over here because we can have duplicate items inside the topple and let's just say 2 3 4 and five no errors now when I print my a here I have this tle now to show you how you can use these methods you just write a DOT count and inside this I'll just write one and it will return the number of times one has been written inside the topple which is six similarly the next method that we have is index so to check the index value at a particular element I'll just write five over here and it will return the value of the index at that particular element but what if there is a duplicate member so I'll just write a or index I already know that one is written multiple times inside the double I'll just write one over here so it's going to return zero because it will return the index value of the first item that is being encountered even though we have the count as six for the element one it will give the index value as zero only so this is all about the tle methods let's take a look at the next topic that we have which is list versus tle so I'll give you a few different points so first of all a list is used for homogeneous data types and a tle is generally used for heterogeneous data types a list is mutable in nature and tupple is actually immutable in nature which helps in Faster iteration as well so is basically faster when it comes to iteration like you're working on for Loops or any other Loops for iteration statements so if you're using any iteration statements topple is much faster than a list and a list does not have any immutable elements but immutable elements can be used as a key for a dictionary while we are using a topple last but not the least we have no guarantee that the data is right protected inside a list but if you're using a topple implementing a topple with data that does not change guarantees that it is right protected so these are a few basic differences between list and topple so let's take a look at the next topic that we have which is the tupple Constructor it is possible to create a tle using a tle Constructor as well I have shown you the two different approaches you can follow to create a topple but there is a topple Constructor which we can use to actually create a topple so let's take it up to jupyter notebook again I'll show you how you can use the tole Constructor okay let's just say we have a list guys and I have these values 1 2 3 so this is my list and when I print my list over here I have the values 1 2 and three so using this topple Constructor I can actually change the list into a topple guys so when I run this no errors now when I print B over here it will have all the elements inside the list but this time it's a tle so we can actually use a tle Constructor to change a data type for type casting and it can be used to create tole as well so this is all about tle Constructor let's take a look at the next topic which is a few other examples so I'll be showing you two examples which is iterating through a topple and a membership test on a topple so let's take it up to Jupiter notebook first of all I'll iterate through a topple so let's just say I have a topple guys with a value until 9 and let's say for I in a print I so this is how you can iterate through a apple using a fall Loop or you can use any other loop as well and this is a very basic example let's take a look at the next example which is a membership test so for the membership test you can use the membership operator which is in and in Python we can check whether an element is present in a tole or not so the following example is going to show you how you can check if an element is present in a tole or not so we'll use this a only so let me just try to print this a okay we have the same tle I'll just print it basically so I'll check 9 in a which is true and I'll just try to check if 10 in a which is false and I'll check if a string in a and I forgot to tell you guys it's not necessary that you have to use the integers only you can use the string or any other data dve inside topple like we have used the list Data Drive as well let's dive into a quiz question how do you create an empty tupple in Python options are given on the screen and if you know the answer please leave it in the comment section below now that you understand tles let's look at sets in Python here you will discover how to use sets to store unique items and perform mathematical operations a set is basically a data structure guys which is a collection of unordered elements all elements in a set are unique which means every element is present just once now these values can be of any data type but they are not indexed and because of this you cannot perform indexing operations such as slicing on sets so now that you know what are sets let's move on and see when to use sets in Python sets can be used when the order of data actually does not matter but the only concern is your data elements need to be unique so now let's move on to see how to create sets in Python to create sets in Python you can use two methods the first method is to use the curly braces and the second is to use the set Constructor I have a small example where I've created a set a using curly braces and a set B using the set Constructor now let's move on towards a Jupiter notebook and create some sets in Python the first thing I'm going to do over here is change the name of my notebook you can give any name of your choice and rename it like I've already told you you can create sets in two ways the first to use curly braces and the second to use the set Constructor let's just create some sets using both these methods I've created a set a using curly braces and then I've specified some random values to it you can also notice that all these values are of different data types after that I've created a set B using the set Constructor this set Constructor has converted a list of values into a set hope you're clear with how to create sets now let me just show youall how to create an empty set using the set Constructor all you have to do is give some name to your set say for example C and use the set Constructor without passing any values to it and hit run now when you print this set you can see that the set is empty it has returned an output which is an empty set so I hope you're clear with how to create sets in Python now let me just show you all what are all the methods you can use along with sets to do so you can use the dir method and Supply the name of the set as a parameter to it when I used D and passed a as a parameter which is a set that I've already created it has returned a number of methods as its output so all these are the methods you can use along with sets now let's get back to our presentation and see what are the operations we are going to perform in this session today first of all we'll be finding in the length of a set and accessing its elements after that we will be adding or updating elements of a set and then removing and deleting elements from it following that we'll perform the mathematical operations that are union intersection and difference of sets now let's move on towards the first operation of this session which is finding the length of a set to find the length of a set you can use the Len method the length of a set is the number of elements that are actually present in that set and this length function will return an integer value which is equal to the number of elements present in the set I have a small example where I've created some random set with the name my set and I've passed some values to it after that I've used the Len function and passed the name of the set as a parameter now let's go to our jupyter notebook and see what happens when I do this I've already created set a b and c I'll just reprint my set a over here so that it's easy for us to refer to it now let's find the length of a when I used Len of a it has returned seven as the output which is equal to the number of elements present in my set a now let's get back to our presentation and see how to access elements of a set since set contain unordered elements you cannot use index values to access its elements but you can Loop through it to access the elements of a set I'll just jump onto my Jupiter notebook and show you all how to access set elements ments I'll reprint my sets A and B over here I've used the for Loop to access the elements of set a all I've done is for every element present in a print that element and as you can see in the output all the elements present in a have been returned one after the other now let's get back to our presentation and see how to add elements to a set to add elements to a set you can use either the add method or the update method now this add method will allow you to add a single element to your set but the update method will allow you to add a list of values to your set I'm going to be showing you how to use both these methods in this session so here is my Jupiter notebook when I use the update method I've passed a list of values to be added to the set C but here I've passed three again and three has been added it just once and it's not been repeated again this is because sets contain unique elements and there is no second copy of one element present in a set so I hope you've understood how to add elements to a set now let's move on to understand how you can remove elements from a set to remove elements from a set you can make use of the remove discard or the pop methods the remove method takes one parameter which is the element to be removed from your set now in case that element is not present in the set this method is going to throw an error the question is what if you're not sure if some element is present in your set or not but you want to make sure that this element is not present and your program does not throw an error in this case you can use the discard method the discard method takes one parameter which is the element to be removed and in case that element is not present in the set this method will not throw any error now moving on towards the pop function the pop method removes a random element from your set now let's get back to our Jupiter notebook and use these methods I'll reprint all the three sets over here first I will use the remove method I've used the remove method and I've specified 2.4 to be removed from the set a when I print the set a 2.4 is no more present in my set now let me try to pass some value that is not present in the set a when I use a. remove 6 which is not present in the set a it has thrown an key error and it's specified that six is the key which is not present in the set a so I hope you've understood how to use the remove method now let's use the discard method and see what happens when I used b. discard 3 it has removed three from the set B now let's try to give some parameter to the discard method which is not present in set B when I used b. discard 90 it has executed but it has not thrown any error so I hope you're clear with both these methods now let's try to use the pop method when I used a. pop it has popped some random value from the set a and it has returned it as the output of here one is no more present in the set a so I hope you're clear with how to add and remove elements from a set now let's move on to our presentation and see how you can find the union of sets Union of sets refers to the concatenation of two or more sets into a single set but in case you have any common values in these set the resulting set will contain just one copy of the common element you can perform the union operation in two ways One is using the pipeline symbol and the second is using the union method I have a small example where I've created a set a and b and then I've used the pipeline symbol and the union method to find the union of these two sets let's go to a Jupiter notebook and see how this works I'll reprint my sets a b c over here I've used the pipeline symbol to find the union of A and B all the elements that are present in A and B has been returned as a new set which is the union of A and B but the common element are just printed once now let's see how to use the union method to perform this operation I've used the Union method to find the union of A and B now let's try to find the union of three sets using both these methods as you can see in the output I've used the pipeline symbol to find the union of three sets and then I've used the union method to find the union of a b and c so I hope you're clear with this now let's get back and see what is intersection of sets the intersection of two or more sets is the formation of a new set consisting only of the common elements that are present in all these sets you can perform this operation in two ways One is using the ersin symbol and the second is to use the intersection function I'll be showing you all how exactly to do this on our Jupiter notebook I've used the ersin symbol to find the union of A and B and you can see over here the elements that are common between the set A and B are four and A B C hence the output now let's try to use the intersection function I've determined the intersection of a b and c using the intersection function and the resultant is a string which is present in all these sets so I hope you're clear with both these methods now let's get back to our presentation and see what is the difference of sets the difference of sets produces a new set which contains all the elements that are present in one set except the common elements to make you all understand this concept clearly let me jump on to my Jupiter notebook to find the difference of set you can use either the minus symbol or the difference method first over here I'll be using the minus symbol when I found the difference of a minus B I've got all the elements that are present in a but not the common elements of A and B when I used B minus a a set has been returned which contains all the elements of B except the common elements of b and a so I hope you're clear with what is the difference of sets now let's use the difference method to do the same I've used the difference method to find a minus C and as you can see all all the elements present in a but not the common elements of a and C have been returned as my output you can use the difference method to find the difference of three sets as well when I found the difference of a minus B minus C using the difference method only one element has been returned which is present in a and not present in B and C hope you're clear with this now let's move on towards our final topic of this session which is the concept of a Frozen set a frozen set is a set whose values cannot be modified which means when you freeze a set it becomes immutable to create Frozen sets in Python you can use the Frozen set method as you all know I've created a set a just make a note guys that you cannot add or remove values from a frozen set as you all know I've created a set a which is a normal set and I've been using it to add and remove values from it now let's freeze this set I've created a new set D which is a frozen set and I've supplied the values of a as a parameter to this Frozen set Constructor now let's see what happens if I try to add some values to this Frozen set when I used d. add3 it has returned an attribute error which says Frozen set object has no attribute add therefore Frozen sets are immutable and you cannot change the values present in the Frozen set Frozen set helps to serve as a key in a dictionary now let's jump into a quiz question how do you create an empty set in Python options are given on the screen and if you know the answer please leave it in the comment section below after sets we will move on to the dictionary in Python you will learn how to create and use dictionaries to store data in key value pairs making data retrieval efficient so what is a dictionary in Python it is a collection data type just like a set or a list but there are certain features that makes dictionary unique so let's take a look at the features of python dictionary guys first of all it is unordered and we can change values in a dictionary as well since it is mutable also it has key value pairs which is like a map that we have in other programming languages and it is indexed as well since the keys are distinct and can be used as indexes to access or change any values in the dictionary a dictionary does not have any duplicate members as well now that we know what dictionary in Python is let's talk about why we use a dictionary in Python first of all the reason would be it is unordered and stores data like a map so it is one unique feature that python dictionary has and it also contains the key value pairs unlike any other data type or object in Python it is almost similar to a real life dictionary where we have distinct values and corresponding to these values there are respective definitions in case of the dictionary even though there are no duplicate members we can mention duplicate members in the values but the keys has to be unique in order to access these members since there are no indexes also we use the keys as indexes when accessing these elements let's try to understand how we Implement a dictionary in Python so first of all to declare a dictionary in Python we have to use the curly brackets just like you can see in the example here I have the dictionary with the name my dictionary and inside those I have the key value pairs inside the curly brackets so let's take it up to py charm guys to understand how we Implement a dictionary in Python let's enter the presentation mode guys so we will try to implement a dictionary here let's take the name of the dictionary as a so inside the curly brackets I can give the key value pairs so I'll give one as my first key so when I am specifying the key value pairs I have to use the colon to separate the key from the value now I'll give one value over here now when we are declaring a dictionary we have to separate these key value pairs with a comma I'll give another key give it a value let's say data science I'll give one more key and give it a value let's say python so this is my dictionary guys this is how you actually Implement a dictionary I have declared a dictionary over here now let's try to understand how I'm going to access these elements so I'll just write a inside the square brackets I'll specify the key Val value so I'll put it inside a print statement guys now as you can see when I run this I will get the value that is specified in the first key value which is Eder I can simply just print all of my dictionary guys so this is how I'm going to get the output as when I print the dictionary that I've just specified now to access these elements I can also use the get function and inside the get function I'll just specify the key value and when I run this I will get the same output as I was getting using the square brackets guys so this is how you access elements inside the dictionary now I can also replace values inside a dictionary guys since it is mutable so instead of data science let's say I want machine learning so what I'll do is I'll just specify the key value and I'll specify the value that I want to replace it with now when I print this you will see the replace value inside the dictionary as you can see here I have replaced the value inside the dictionary guys now if I want to add one more value inside a dictionary what I'm going to do is I'll just specify the key value that is let's say four because we don't have four over here so instead of machine learning I'll add the value data science that I have just replaced now when I print my dictionary here let's see what all values I will get I will get one more value that I have just added which is data s so this is how you actually Implement a dictionary guys and to access these values you can either use the square brackets and inside those square brackets you can specify the key value or you can just use the get function and inside the get function and inside the get function you have to specify the key value as well so now that we have understood how we can Implement a dictionary in Python let's try to take a look at the operations that we have in Python dictionary guys so as I have told already told how you can actually add an element to your dictionary just like this I have specified a key value and given it a value and then there is a replacing element which I have already shown you guys so these are all the operations that we have in Python dictionaries so we will look at them one by one guys so let's take it up to pycharm and understand these operations guys so we'll once again enter the presentation mode so we have a dictionary over here guys so first of all let's talk about clear so when I use the clear what it's going to to do is it is going to remove all the elements from the dictionary so when I run this so I have a dictionary guys that I already specified so let's try to print the dictionary first so you will understand what all these operations are going to do so I have this dictionary which has these values all right so I'll do one thing I'll use the first operation that is clear let's see what it does to our dictionary guys when I run this okay so now when I print my dictionary let's see what all value I'll get it is saying that it is empty because the clear function has actually deleted or removed all the elements from the dictionary so this is what clear does guys now let's take a look at the another one which we have also I would want to declare this dictionary once again and when I print this I should be getting all these values again yes I'm getting these values so it would be fine if I do one more thing so I'll just use the copy over here so what copy does is it returns a copy of the dictionary guys so let's say when I print B over here what is going to happen it is going to show me the copy of this dictionary that I have just specified over here using the copy function so let's take a look at the next one we have which is the values so when we are using the values function what it's going to do is it is going to return all the values inside the dictionary guys so when I run this it will print all the dictionary values inside a list which is Eda data science and python so we'll look at the next one we have which is the update function so what does update function do update function actually updates the values of the dictionary with the specified key value pairs so let's say if I use update just like this what will happen we have no updates which it is showing that we haven't updated anything so this is what update does guys if we have made any updates it will update the changes into the dictionary so we look at the next function that we have which is actually get function I've shown you how to use the get function we'll just use the get function to get the values and inside this I just specify the key value and it will return the value with the specified key which is actually urea so this is how you actually access the elements using the get function next one is the items function guys so I'll just use items over here and inside this I will get the list for a topple of each key value pair guys so let's run this so when I run this I'm getting coule of each key value pair as you can see over here I have two then I have the value then I have one more key so this is a topple of each key value pair which we can get using the items function now coming back to the next one that we have which is the keys function so what it will do is it will actually return all the keys inside the dictionary that we have which is 1 2 three guys so this is all about Keys function guys so let's talk about the pop function guys so when I use the pop function what it will do is it will actually pop the value with the specified key so I'll just pop this from the dictionary with the value three so as you can see I'm getting that value over here guys now let's take a look at the next function that we have or the operation which is pop items guys so when I'm using the pop item function I can actually remove the last inserted key value pair so I don't have to specify any values over here as you can see I'm getting the topple of the last key value pair I have specified inside the dictionary so this is what pop item does now the next function that we have is set default guys so what set default does is it Returns the value of the specified key if the key does not exist we can insert the key with the specified value so I'll specify the value over here let's say one now when I print this I'm getting Eda as well so when I specify the next key it is showing me okay it's a syntax error I'm getting the next value so this is what set default is used for which Returns the value of the specified key guys so this is all about the operations that we have in a dictionary guys there is one more thing to discuss about the dictionary guys which is the dictionary Constructor so the diction Constructor is actually used to declare a dictionary guys so let's take it up to py Cham again so I'll show you what a dictionary Constructor does so I'll use a I'll use okay I'll use my dictionary as my variable dictionary name and I'll use the dictionary Constructor over here I'll specify the values so what I'm going to do is I'll just specify the values I will use the keys as let's say key one only and then I'll give it a value let's say urea now I can give another key value let's say two and I'll give it a value let's say python now let's see if I can get a dictionary from this so using the dictionary Constructor let's see if we have actually implemented a dictionary over here so as you can see I have declared a dictionary using the dictionary Constructor guys so when I run this I should be getting a dictionary here so as you can see I have declared a dictionary using the dictionary Constructor also one more thing I have missed over here when I was explaining the operations guys so which is the from Keys operation so I'll declare one more dictionary over here give it a value let's say one two I'm giving it a random values guys don't be alarmed now when I'm using the from Keys keyword what I do is I'll just say a DOT from okay we don't have a over here so I'll write a from keys I'll specify my dictionary over here so let's see what happens guys okay I'll so I'll just use the print statement and inside this I will use the from keys and inside this I'll specify my dictionary let's see what happens when I run this so I'm getting a dictionary with the specified keys and values so as we don't have any key1 key2 inside this so we we are getting the none value over here so this is what from keys does inside a dictionary guys so now that we have actually learned what is a dictionary and how we can implement it in Python and all sorts of operations that we can perform on a dictionary let's try to understand what our nested dictionary guys so for this I have a problem statement guys so now that we know that ICC Cricket World Cup is just around the corner guys so what we'll do is we will Implement a dictionary with the stats of the 15 members from the Indian cricket squad for the World Cup 2019 and we will use the concept of nested dictionary in the use case so so what we'll do is we'll Implement a dictionary first and then we will make the unique keys to access those values when we are actually getting the elements from the dictionary and then we will store the data inside the dictionary and we will also import a pandas package and convert those data into a data frame for better display statistics so let's take it up to py Cham guys so okay let's exit the presentation mode so over here I have the value or the dictionary that I implemented so let's Che it up to presentation mode again so as you can see I have this module that I have actually imported from pandas and I've given it an alas as PD so we'll talk about this later so this is my dictionary guys in which I have made four more dictionaries guys which is actually are estate dictionaries so first key is batsman inside the batsman key I have all those batsman like RIT Sharma sikar daan and vat kohle and inside those values I have one more dictionary in which we have the statistics for all those matches runs average highest score so actually inside this batsman key I have two more dictionary guys so this is the concept of nested dictionary so similarly I have made it for allrounder and we have Wicket Keepers and Bowlers as well so this is my dictionary guys that I have actually stored all the data using the dictionary or as you can say nested dictionary and then I have all these statements I have written in which I have converted the data inside the dictionary into a data frame guys so I have this print statement so first of all let me print the batsman squad in which we will get the values for all the batsmen that we have inside the World Cup squad so as you can see I'm getting a data frame over here so I have these values we have Rohit Sharma shikar daan and vat kohi so as you can see we have average highest score matches and runs over here so for Virat kohi we have more than 10,000 runs shikan has 5 ,000 runs and R Sharma has around 8,000 runs guys so let's try to understand more from the dictionary that I have just mentioned over here we have got all the batsmen now we will try to get all the bowlers so I'll just print this statement and it will show me all the bowler statistics which is Kip yadav Muhammad shami buhar Kumar Yuzu chel so we have all these statistics in which we have average we have best figures then we have matches and wickets as well so as you can see we have bhes Kum with the most wickets which is 118 wickets guys so this is what you can actually do using the nested dictionaries guys as you can see this is an unordered data but we have key value pairs which actually helps in retrieving the data very easily guys so let's say inside bowler I want jasp brra or for allrounder I want hardik Panda all these statements I can use it for getting all those values inside a data frame now let's take up the another quiz question how do you add a new key value pair to an existing dictionary in Python options are given on the screen and if you know the answer please leave it in the comment section below with dictionaries covered it's time to discuss python Loops this topic will teach you how to use Loops to perform repetitive task in your program if you have any questions or need clarification on any topic we have covered please comment below and we will assist you right away now what are loops loops basically allows us to execute a statement or a group of statement multiple times let me explain you this with the help of an example that is present in front of your screen now over here what happens the control comes here and checks the condition so if this condition is true it'll go on and execute the conditional code that is here this is nothing but the statements that are present inside the loop so it will execute that and again it'll go back and check the condition so if the condition is still true then again it will execute the conditional code of the statements present inside the loop and it will keep on repeating until this condition becomes false and the moment this condition becomes false the control will move out the loop and it'll execute the statements that are present after that Loop now one thing to notice here guys is that there can be two kinds of Loops one is finite this is actually the flowchart for the finite loops and another can be infinite now in infinite Loops what happen the condition will never be false so at that time the control will never come out the loop so it will keep on repeating and it will never stop that is what infinite Loops are so basically the condition will never be false and due to that the loop will be executed infinite number of times now there's one more way in order to categorize Loops that is called post test and pre-test in post test Loops what happen the control will first enter the loop and then in the end it will actually check the condition but in preest Loops the control will enter the loop only when the condition is true so so the condition is checked in the beginning of the loop in pre- test Loops but in post test Loop the condition is checked at the end of the loop now in Python there are no post- test Loops present there are only pre-test Loops so we'll focus on pre-test Loops in today's session so we'll move forward and we'll see various type of Loops that are present in Python so python basically supports three kinds of Loops one is V for and nested we'll look at all these Loops one by one and I'll explain you with examples as well so first we'll have a look at while loop so while loop is basically used when you don't know how many iterations are required so let me explain you this with the help of the flowchart that is there in front of your screen now over here what happens the control will move inside the loop only when this while condition is true and when it is true it'll execute the body of the loop and then again it'll go back and see whether the condition is still true or not if it is still true then again it will execute the body of the loop and it'll keep on doing that until the condition becomes false and the moment the condition becomes false it will come out of the loop and execute the statements that are present after the loop now this is a Syntax for while loop first you need to write while then you write the expression of the condition then you give a colon and the statements or the body of the loop now why we use V Loop basically I've told you earlier as well while loop is used when you don't know how many iterations are required so you don't know how many times you need to execute the statements that are present inside your Loop Loop so that is the reason why we use y Loops now let me show you that with the help of an example I'll open my pie charm and I'll give you a very basic example of using Y Loop and after that I'm going to increase the complexity of the code so first we'll see a very small introductory example of Y Loop in which I'm going to print the integer values between 0 to 9 that won't include N9 so it'll print 0 1 2 3 till nine but it won't include nine so let me open my py charm and show you how to do that now this this is my pie charm guys so over here as I've told you earlier as well I'm going to print the integer values between 0 to 9 but that won't include 9 so for that what I need to do is I need to First Define a variable let me name it as count and I'm going to initialize a value to it that is zero now after that I'm going to use a y Loop and I'll write while and then I'm going to give a condition which says that when count becomes greater than N9 it should come out of the loop all right so now what I'm going to do is I'm going to just type in print Let It Be number colon comma print count right now I'm going to increment the value of count count equal to count + 1 yep now when I come out of the loop I want to print say goodbye yeah looks fine now let me tell you what I've done here I've defined a variable and I've initialized the value Z to it after that I have used a y Loop in which I've given a condition that says that count should always be less than 9 because I want to print values between zero till nines which won't include nine let me tell you that so my condition says that the loop should be executed only when the count value is less than nine the moment it becomes greater than nine then the control should come out of the loop after that it's just a general syntax I have given a colon and then I have written a print statement that will print the count value and after that I have increased the value of my count by one and finally when the control comes out of the loop I want to print goodbye so let us see whether it works or not I'm going to run it and as you can see that it works so we have 0 1 2 3 4 5 6 7 and8 and finally when the control went out of the loop it has printed goodbye this is just a very small example guys now let me go back to my slides now the example that we just saw was a very simp simple example so I'll increase the complexity a bit and I'll give you one more example so let us move forward with that so over here what I'm trying to do is I'm trying to code a little guessing game all right so what happens in this guessing game so there will be a random number that will be generated between say 0 to 20 and you need to Guess that number so the number that you have guessed is less than that random number then it will print number is too small if you have guessed a number that is greater than the random number then it will print that number is too large and the moment you guess the right answer you'll exit the Y Loop and you have won the game basically so it's just a pretty simple example but this is a perfect example in order to show you why we use y Loop because if you notice here I don't know how many iterations are required in order to guess the correct answer so at that time y Loop is a perfect solution to this problem so without wasting any time I'll actually open My Pie charm and show you how to execute this so this is the code here guys let me explain you each and every line that is present here now what happens first I need to import a module that is called random in order to generate a random number now over here I've defined a variable n and I've given a value to it that is 20 because I want the random number that is to be generated should be between the range 0 to 20 now I've taken one more variable and I've named it as to be guest and over here it should be an integer type I've written int and this logic will generate the random number that I'm talking about and this will be generated between the range 0 to 20 so how it'll be generated it'll be generated with the help of random module that we have imported so it'll be n random. random + 1 this will actually generate a random number between 0 to 20 so after that what happens I've defined one more variable guess and I have assigned a value to it or initialized a value to it zero all right so now comes the Y Loop now in y loop I have given a condition which says that the number that I have guessed if it is not equal to the random number then enter the loop now once you enter the loop you need to input the new number the number that you want to guess again now if that guessed number or the number that you are guessing is greater than zero then again there'll be one more if condition which says that the number that you have guessed is greater than the number that has been generated or the random number that has been generated then print number is too large and if the number that you have guessed is actually smaller than the random number generated then print number is too small now there's one more condition that is else which means that when the number that you have guessed is less than or equal to zero then that means you're giving up so it'll break it'll come out of the loop and it'll print sorry that you are giving up that's when your game gets over and you have lost it finally if you have guessed the correct number then it will print congratulations you have made it so I hope you have understood the code that I was explaining here so let us go ahead and execute this and see what happens all right so it asks me for a new number so it has to be between 0 to 20 so yep I'll type 10 and let's see what happens so it says number is to small that means it is between 10 to 20 how about 13 all right so I've guessed the correct number and it says congratulations you have made it now over here as you can see that it took only two iterations for me in order to guess the correct number but what if it would have taken more iterations I mean I'm pretty unclear how many iterations it will take for me so that is the reason why we use y Loop because we don't know how many iterations are required now we can run this program again and I can show it to you once more ask a new number so I'll just type and say 14 it says number is too large so I'll type in 11 again the number is too large that means it is between 0 to 11 so how about eight guys number is too small so now now as you can see that already three iterations have occurred and uh for the fourth iteration definitely the random number will be somewhere between 8 and 11 so how about 10 so congratulations you have made it and the control came out of the Y Loop and it has printed congratulations you made it so we'll move forward and see for Loops in Python so for Loop is basically used when you know the number of iterations that are required unlike y Loop where you are not sure about the number of iterations that are required in for Loop you know how many times the statements that are present inside the loops need to be executed so for Loop provides you with a syntax that will include three Fields basically or you can say three informations so first will the Boolean condition then comes the initial value of the counting variable and then the incrementation of the counting variable so as you can see from the syntax as well first you write for name of the variable in the range then you specify the range in which that variable should be or and then you specify the range that means from which point till which point it should be executed so you know the number of iterations required then only you use for Loop now over here as you can see from the flow diagram itself the control comes to this and it'll see the item from the sequence it'll execute the statement go back again and then from the range it'll pick up the next item again it'll execute the statement again go back and then from the range it'll pick up the third item and it'll keep on executing until the range becomes over or that is the last item from the sequence so when there are no items in the sequence it will go on and execute the statements that are present after the for Loop so this is how for Loop Works guys now let just give you a very small example of how for Loop works I'll open my py charm again and I'll start with a very small example and then I'm going to increase the complexity of our code like I've done that in while loop now over here what I'm going to do is I'm going to first Define a list and I'm going to name it as fruits so what all fruits you like guys I'll first type in mango then I like grapes and finally I'm going to write in say apple yep so this is my list which contains three fruits mango grapes and apple now I'm going to define a for Loop and over here what I'll write I'll Define a variable say fruit for fruit in fruits give a colon print current fruit and type in fruit now when you come out of the loop just print again goodbye so I have declared a list and the name of that list is fruits now that fruits list contains elements which are mango grapes and apple now after that I have defined a for Loop which says that for a variable name fruit in fruits so this will give me the range fruits will give me the range as you know that in the fruits list there are only three fruits so I know it'll iterate only Thrice first for mango then for grapes then for Apple so this is the difference between the V and for Loop in for loop I know that it'll take only three iterations after that print the current fruit that's all and when the control moves out of the loop print goodbye it's pretty easy guys so go on execute this and see what happens so yep the current fruit first is mango then comes grapes then comes apple and then finally print goodbye so what I'm going to do is I'm going to increase the complexity now as I've done that in while loop as well so I'll show you an example first let me go back to my slides so what I'm going to do in this example I'm going to calculate the factorial now one thing to notice here guys again in factorial also I know how many iterations are required because if you see if I'm calculating the factorial of five and I know that I need multiplication five times first I need to multiply five with four then four with three then three with two and then two with one so this way I require only four iterations so I know the number of iterations required so it's a very good example in order to show you where we should use y Loop and where we should use for Loop so let me go back to my py charm and execute this practically so this is the code in order to find the factorial of a number so over here what happens first I need to input the number that I want to calculate the factorial of after that I've defined a variable factorial and I've initialized a value to it which is one now I have defined a condition if the number that I've entered is less than zero then print the number must be positive because I can't calculate the factorial for negative numbers right and again I have given one more condition which says that if number is equal to equal to zero then factorial is equal to 1 and then lse condition says that when number is greater than zero then I've used a for Loop which says that for I have defined a variable I in range one to num + one when I write num plus one the range will be between 1 to num + one but it won't include num plus one so it'll only be including one till num all right so after that what I've written factorial is equal to factorial into I so factorial was one earlier then it'll multiply by I I will also be one in the beginning and then again it'll go back and it'll become two s Sly it will keep on increasing until it becomes numb so till that time it will keep on executing the loop and the moment it becomes equal to num it'll come out of the loop and it will print the factorial value so let me go ahead and execute this and show you if it works or not so I need to enter the number so let's say I want to calculate the factorial of three which is six so if I want to enter one more number so what I can do is I can start it once more so what I'll type I can type again four so it prints 24 which is absolutely correct so we'll move forward and we'll see what are nested Loops in Python so python basically allows us to use a loop inside another loop for example you can use a for Loop inside a for Loop or you can use a y Loop inside a y Loop and at the same time you can use a y Loop inside a for loop as well and a for Loop inside a while loop as well so that is basically what is called nested Loops now we'll have a look at the example of nested Loops as well don't worry so let us move forward and see one example of nested Loops now over here what I'm going to do is I'm going to write a code in order to simulate a bank ATM all right so for that I'm going to use nested while loop and what will happen first you need to enter the four-digit pin and then you can perform the following functions you can check the balance you can make a withdrawal you can deposit some money and you can even if you don't want to do anything you can tell the machine to return your card as well so so let me show you how it is done I'll open my P charm once more so this is a code that I have written in order to simulate a bank ATM I'll explain you each and every line so don't worry about that so first line is nothing but a print statement that says welcome to iron bank of browers ATM all right and then I have defined a variable restart and I've assigned a value to it that is y similarly chances I've assigned a value that is three and this is the balance that I'm going to initialize that is 67.1 for notice you over here you won't get more than three chances in order to write the correct password now comes the while loop which says that when chances are greater than or equal to zero at that time what it'll do you need to enter the pin so you need to input the four-digit pin that you have and if that pin is 1 2 3 4 then it'll print that you have entered the correct pin now comes one more while loop which says that while restart should not be in this particular tle that is the value of restart should not be n capital n o small n o or capital N so it should not lie within this particular sequence that is n capital n o no and N but we know that restart value is y so it'll enter the Y Loop now over here what will happen it'll give you four option first option is in order to check your balance for that you need to press one to make a withdrawal you need to press two in order to pay some cash or you need to deposit something you need to press three or you want your card back you need to press four so these are the four options that will be given to you so when you choose option one it will print the account balance so over here as you can see that your account balance is and the balance that is there in your account after that it'll ask you for restart so you need to input that value so that will say would you like to go back and if your restart value lies in this particular tle then it will break and it'll print a thank you statement but if you want to continue or you want to go back then you can press anything else apart from small n n o or this no or capital N so if you press any other button apart from these it'll actually go back and in the v statement as you can see it says that it is not present here so it'll give you all these four options once more now after that what if you choose the another option in which you need to make a withdrawal so for that what will happen you need to enter the amount that you would write to withdraw which can be a float number it cannot be an integer number so that's why I've used float here so you need to enter that value and once you enter that value it'll check whether it is in this particular list or not that is 10 20 40 60 80 or 100 Now by default it'll give restart why because you need to enter the amount once more so again it'll go back and it'll give you all four options so you can choose that withdrawal option again and you can choose the number which is present in this particular list now when you choose withdrawal equal to equal to 1 at that time it'll again ask you please enter the desired amount so this is for option two now when we talk about option three it is pretty much similar to the couple of options that we have discussed before so it is pretty much similar to that over here again whatever the amount that you want to pay in how much amount that you would like to pay and balance plus the amount that you are depositing so it'll print the balance that will be equal to balance plus the amount that you're depositing again it ask you for restart if you press anything apart from this particular tle then it'll go back to the while statement and it'll give you all these four options similarly for option four as well now what happens when you enter the incorrect pin so there's one more condition in the end which says that if the pin that you have entered is not equal to 1 2 3 4 then it will print that incorrect password and it will decrease the chances by one so earlier you had three chances if you press the incorrect pin once it'll decrease your chance and make it as two again if you write the incorrect password then again it will make it as chances equals to Chances minus one which will become one and if the third time also you do the same thing then the chances will become zero and the moment it become zero then it will print no more tries break it'll come out the loop that's all guys so let us go ahead and execute this and see what happens so please enter your four-digit pin so I'll just write 1 2 3 4 and it give me four options which is one for balance two for withdrawal three for paying four to return a card so if I want to check my balance I'll put in one so it has printed my balance which is 6 7.14 and then the restart value that I was talking about it is asking for that let me just make it big for you yeah would you like to go back so if I press n here it'll come out of the loop and it will break and if I press anything apart from small n capital N small n or capital N it'll actually go back and ask give me all the four options that there so if I press y it'll again give me all the four options that are there you can see that press one so again if I want to make a withdrawal I'll press two how much amount that I would like to withdraw say I want to withdraw 10 so my balance has reduced from 67.1 4 to 57.14 so would you like to go back so I'll again press Y and it'll give me all four options if I want to pay in something that is I want to deposit something I'll press three how much amount that I would like to deposit I'll say 10 so my balance became again 67.1 4 again it is asking me would you like to go back no I don't want to go back so I can type in N so yep so it says thank you and again asking me for four-digit pin so let me show you what happens if I write the incorrect pin say if I write 11 one incorrect pin if I write that pin again again incorrect again incorrect so we have no more tries it'll come out since I've exceeded the chances that I was given so so I was given three chances I couldn't write the correct pen in those three chances so it'll come out of the loop and it'll stop so this is an example of nested V now let me go back to my presentation and I'll show you an example of for loop as well so this is an example of nested for Loop so over here what I'm going to do is I'm going to write a code in order to print the Pythagorean number between a particular range so what happens is suppose if I want to enter the number 20 that means I want the Pythagorean number between 1 to 20 so Pythagorean numbers are nothing but the integers which satisfy a square + b² is equal to c² so at that time it'll print all the Pythagorean numbers that are possible between 1 to 20 3 4 5 you can see that 3 Square 4 square is equal to 5 Square 9 + 16 is = 25 similarly it goes for 5 12 13 6 8 10 8 15 17 9 12 15 similarly for 12 16 and 20 don't worry guys I'll go back to my P charm and I'll explain you how you can do that so this is the example of nested for so first over here I need to import certain modules in order to use a square root function so from math module I'm going to import the square root function after that ask me for the number in the example if you can remember in the slides where I've written 20 so it has printed the Pythagorean numbers between 1 to 20 that same number it will ask me and it'll print the Pythagorean numbers between 1 to n so whatever the number n that I'm going to put in or given input after that it'll run a for Loop and it will say that for a which is a variable in range 1 to n + 1 that means 1 to n that means 1 to n + 1 but don't include n + 1 after that there's one more variable B which is in the range a comma n that will not include n it'll only include till n minus1 so the square root C squ I've defined one more variable c² is is equal to a exponent 2 or a to the^ of 2 similarly B ra to the^ of 2 all right and then what I'm going to do is I'm going to calculate the square root and then what I'm going to do is I'm going to Define one more variable C and it'll be an integer that will be the square root of c² so if that c square is minus c² is equal to equal to Z then print a b c it's pretty simple logic guys okay I'll explain it once more Neil so this is an example of nested for so over here what I'm going to do is I'm going to first import the square root function from the math module after that I'm going to input a number so if you can remember in the slides I've given it as 20 so it will print the Pythagorean numbers between 1 to 20 over here also it'll print the Pythagorean numbers between 1 to n so whatever the value of n you input that will be depending upon it so the Pythagorean numbers will be depending upon the values that you input so it'll be printing the Pythagorean numbers present between 1 to n after that I'll run a for Loop which says that for a should be in the range 1 to n + 1 that will not include n + one guys it'll only include n so one till n + 1 but don't include n + one after that I've defined one more for Loop which says that for B in range a comma n it won't include n it will be till only nus1 I've defined one more variable here which is equal to ccore s that is = to a² + b s now after that I've defined one more variable C and this will be actually the integer of the square root of the ccore square all right so whatever value that you'll get here the square root of that value will be converted to an integer value and will be assigned to C now one if condition I'll be using here which says that if ccore s minus c² is equal to Al to Z then print ABC that means that will be a Pythagorean number so this is a pretty simple logic guys if you have understood it just give me a thumbs up or you can ask me any questions that you have in your mind all right so I hope you have understood the code that I've explained you here now let us go ahead and execute this and see what happens yeah so the first number that I'm going to type in say five and it'll give me all the Pythagorean numbers present between 1 to five so we have only one Pythagorean number that that is 3 4 5 in that range now I'll execute this once more and I'll type in 10 here so we have two Pythagorean numbers that are 3 4 5 and 6 8 10 similarly if I execute it once more and I type in a big number say 25 yeah so we have these many Pythagorean numbers present between 1 to 25 we'll again go back to our slides and we'll have a look at one more example now in this example I'll actually be using a for Loop inside of V Loop so what is this example I want the bulk reservation of train tickets so I have like group of people who are traveling somewhere and I want to give their details such as name age and sex I want that to happen in bulk I don't want to give it one by one I just want it to happen in bulk so for that what I'm going to use is I'm going to use a for Loop inside a while loop as I've told you earlier as well you can even use a while loop inside a for Loop but for now I'll use a for Loop inside a while loop and see what happens so let me go back to my Pie charm so this is the code in which I'll be using a for Loop inside a y Loop so first I have defined a variable traveling so in which you need to input whether yes or no so if you're traveling you'll say yes obviously and then we'll have a while loop which says that while the condition is traveling equal to equal to yes that means if you're willing to travel enter the number of people who are traveling so you need to enter the number of passengers that are traveling and that will be assigned to a variable num now there'll be a for Loop which says that for Num in range one to num plus one but it won't include num plus one enter the name enter age and finally whether the person is male or a female and then print all those values now one more thing here is again It'll ask you whether you have missed someone or not so you need to input that oops forgot someone so at that time you can write in yes if you have forgotten someone that again it'll execute the loop again It'll ask you the number of people traveling and all these details if you ripe in anything apart from yes that means you have not forgotten anyone and it'll come out of the loop so it is a very small example but a very good example to understand how uh for Loop can be used inside the while loop so let me go ahead and execute this whether you're traveling I would say yes I am traveling number of people traveling I would say three name is sorab AG is 78 male all right so again it has asked me for one more name so I'll say Neil AG is 90 male or female male yep so one more name I need to type in say I would type in jogy ag is 98 male or female female and Y it'll print all those details for me so now it is asking have you forgotten someone so if I type in and say yes then it'll again Ask me the number of people traveling that means it again executing the while loop so if I would say the number of people traveling is one and I would type in the name of the person that was traveling so I would just say sidart whose age is 77 and and he's a male yep again it is asked me so if I type in anything apart from yes say if I type n so yep it'll come out the loop and this is how you can actually use a for Loop inside a y Loop now let's take up a quiz question how many times will The Following Loop executes option A 1 option b 2 option C 3 or option D Z and if you know the answer please leave it in the comment section below now that you know about loops let's explore python libraries you will discover the vast array of libraries available in Python that extend its functionality after exploring python libraries we will dive into python numpy this powerful library is essential for numerical computations and working with large arrays so what is numai napai is basically a module or you can say a library that is available in Python for scientific Computing now now it contains a lot of things it contains a powerful n dimensional array object then tools for integrating with cc++ it is also very useful in linear algebra forer transform and random number capabilities now let me tell you guys numpy can also be used as an efficient multi-dimensional container for data for generic data now let me tell you what exactly is multi-dimensional array now over here this picture actually depicts multi-dimensional array so we have various elements that are stored in the respective memory locations so we have one two threes in their own memory locations now why is it two-dimensional it is two-dimensional because it has rows as well as columns so you can see we have three columns and we have four rows available so that is the reason why it becomes a two-dimensional array so if I would have had only one row then I would have said that it is a one-dimensional array but since it contains rows as well as columns that is it is represented in a matrix form that is why we call this as a two-dimensional array so I hope we are clear with what exactly two-dimensional array is so let me open my py charm and I'll tell you practically how to actually create an umpy array so this is my pycharm guys over here the first thing that you need to do is first install the numpy module and how you're going to do that click on file go to settings tab and you'll see the project interpreter option and on the right hand side you'll see a plus symbol just go on and type the module that you want to install so I'm going to install numpy just go there click on it and install packet I've already done that so I'm not going to repeat it so this is my py charm so first thing that I need to do is import numpy as NP now after that I need to create an npy array so for that I'm going to Define a variable let it be a and I'm going to type in here np. array and certain elements inside it so I'm going to put in one two three and print it that's all this will actually print a single dimensional array so 1 2 3 has appeared now if I want to convert this to a 2d array so for that I'll keep this in parenthesis and after a comma I'll add one more element and I'm going to give certain values inside that so I can give say four five and six now go ahead and print this so as you can see that it is now a two-dimensional array so this is how you actually create arrays using numpy module so now I'm going to open my slides and we'll move forward and see what is our next topic now let us see why are we using numpy instead of a list all right so many of you might be thinking why are we using numpy when we have list all right so basically we use numpy because of three main reasons the first thing is it occupies less memory when compared to list then it is actually pretty fast when you compare it with list and at the same time it is very convenient to work with num people y so these are the three major advantages that numpy has over lists and that is the reason why we use numpy instead of list now don't worry I'm actually going to prove it to you practically by opening my py charm so guys this is my py charm again so first thing that I need to do is import numpy as NP and now what I'm going to do is I'm going to import a couple of more modules I'm going to import time and I'm going to import six all right done so our first step is to actually Define a list and the name that I'm going to give to my list is say s and I'll type in here range th000 so what this will actually do it'll actually take all the integer values between 0 to th000 and it will give it to our variable s so this list will contain the integer values between 0 to th but it won't include th it'll be only there till tri9 that is 999 and now I'm going to print the space occupied by this particular list so for that what I need to do is I need to type in print sis. get size of any one element okay so you can give three four five anything I'm going to give it as five any one element and multiply that with the length of my list that's all so this will actually give me the space that has been occupied by the list because sis. get size of will actually give me the memory occupied by one element and when I multiply that with length of my list I get the entire memory that has been occupied by my list now the same I'm going to do with my numpy array as well let me give a name to that I'm going to type in d np. a range and the range will be th000 now a range function is pretty much similar to the range which is there so the same thing will happen here the integer values between 0 to th000 but it won't include th will be present in my variable d so we have created a numpy array now let us print the space occupied by it so the first thing is I'm going to type in here D dot size so this will actually give me the space occupied by one single element and when I multiply that with the length of my numpy array I get the entire memory that is occupied by the numpy array so I'm going to type in here d. item size that's all now go ahead and print this so this actually shows the memory that has been occupied by my list and this shows the memory that has been occupied by my numpy array so as you can see there's a quite a lot of difference between both of them so we have proved our first point that it actually occupies less memory now when I talk about numpy array is faster and more convenient than a list so the next step is I'm going to prove it to you that numpy array is actually faster and more convenient than list so I'll remove all of this and so now I'm going to show you that numpy arrays are faster than list and at the same time it is easier and more convenient in order to work with numpy arrays when compared to list let me show you practically so first what I'm going to do is I'm going to Define a variable say size which is equal to say 1,000 and then I'm going to Define two lists now what I'm going to do is I'm going to add those two lists as well as I'm going to add two numpy arrays which I'm going to Define now and then I'm going to compare the time taken in order to find the sum for list and the sum for numpy arrays so first let me Define two lists and two arrays so my first list will be equal to range size same goes for my second list as well just change the name to L2 and now I'm going to Define to numps A1 equal to np. AR range size go ahead and do the same for the second numpy array as well and change the name as A2 so we have two lists and two arrays and we need to compute the sum of both of these list as well as arrays now before that I'm going to Define a variable say start which is equals to time dot time and now I'm going to calculate the sum so I'm going to save that in result and first I'm going to calculate the sum of list that is L1 and L2 so for that what I need to do is I need to run a for Loop because if I directly write L1 plus L2 it is going to give me a result which is nothing but but the concatenation of both the lists so in order to calculate the sum I need to use for Loop let me show you how to do that first I'm going to type in X comma Y and we have already studied Loops in detail for X comma Y in zip and the name of the two list that is L1 comma L2 that's all so what will happen here it will first take the first element of list L1 and then it'll take the first element of list L2 it'll going it'll calculate the sum and it will store in result and it'll keep on repeating until the range has been exceeded now this is how you calculate sum in list but when you talk about arrays what you need to do is you need to just write in A1 Plus A2 that's all that's why I'm saying that it is more convenient in order to work with numpy arrays when compared to lists now our next step is now our next step is to define the same variable start and initialize it with time. time and now I'm going to find the sum of my two nump y arrays which is nothing but A1 Plus A2 that's all and now print the time taken so print time. time minus start and then multiply it with th000 because by default it'll take it in seconds and I need to convert it into milliseconds now I forgot to actually print the same thing for my list so I'm going to do it over here so this will actually give me the time taken by my list in order to compute the sum and this statement will give me the time taken by my numpy array in order to compute the sum so let us go ahead and execute this and we'll see what happens so it gives me 0 milliseconds because the size is small let me just add a couple more zeros uh let's make it a million now go ahead and execute this now you can notice the difference that there's a significant change lists took 208 milliseconds whereas numpy took almost 67 milliseconds so there's a huge difference between the compute time of list as well as numpy array that's why I say that numpy array are faster convenient and at the same time they occupy less space when compared to list so that is the reason why we choose numpy arrays over list so let us go ahead and move forward towards the next topic that is numpy operations so let me go back to my slides so now is the time to see various operations that you can perform with the numpy arrays so you can find the dimension of your array whether it is a two dimensional or a single dimensional array then you can even calculate the bite size of each element it is pretty easy I'm going to tell you that practically you don't need to worry about that and you can even find the data types of the elements that are stored in your array so if you want to know what is the data type of the elements you can do that as well so let me show you these three operations first and then we'll move forward to the other operations I'm going to open my py charm once more guys let me remove all of this so we have imported the numpy module now what I'm going to do is I'm going to define a numpy array I'm going to name it as a and I'll write here np. array 1 comma 2 comma 3 put that in parenthesis now add one more element say 2 comma 3 comma 4 all right so it's a two- dimensional array now if I want to know whether it's a two- dimensional or a single dimensional array so I'm just going to type in print a do endm and it'll give me the dimension so let me show you that and I'm going to run this so it says two that means it is a two-dimensional array so what if I move this part and make it as a single dimensional array it should give us the result as one let's see if it does that or not and yep it gives us one as a result so this is how you actually calculate the dimension of your array now if you want to find the bite size of each of the elements so what you need to do is instead of endm you can call a function called item size go ahead execute this and you'll get so each element occupies four bytes after that if you want to know the data type that is stored in the array so you can just type in here dtype go ahead execute this it should give us integers integers 32 B all right so this is how you can actually perform these three functions that I've told you in my slides so let us proceed with the presentation now let us move forward and see what are the other operations that you can perform with numpy module so by using numpy array you can actually find the size of your array how you can do that that I'll show you practically you don't need to worry about that so when I say size of the array that means the total number of elements that are present in the array so if this is an array so the total number of elements become four 1 2 3 and four now you can even find the shape of your array now what do you mean by shape so basically the total number of columns and rows now over here we have three columns and four rows so our shape is actually three columns and four rows now let me show you practically how you can do that again I'm going to open my pie charm and show you let me remove this print statement from here now if I want to find the size of my numpy aray I just need to type in print a do size that's all you have to do and it'll give the size of your array so there are three elements so if I go on and add some more elements say four 5 6 7 then if I execute this you'll see that seven elements have up here that means the total number of elements in my array is seven then comes the shape part that I was talking about so in order to find the shape what you can do is you can just type in here a. shape and it'll give you the shape so let us see what happens so it has seven columns but there are no rows so it has given seven comma blank so what I can do is I can close this in parenthesis and I can Define one more element say 8 9 10 11 12 13 14 go ahead and execute this and you can see two comma 7 because we have two rows and seven columns available with us so this is how you can actually find the size of your array as well as you can find the shape of your array now let's take up the quiz question what will be the output of the following python code for I in range 2A 5 print I and the options are option A 2 3 4 option b 2 3 4 and 5 option C 1 2 3 and 4 or option D 3 4 5 so if you know the answer please leave it in the comment section below now let us move forward and see what are the other operations that you can perform with numpy module so we saw how to find the size and the shape of an array so we can perform reshape as well as slicing operation using numpy array now when I talk about reshape what do you actually mean by reshape geogy all right fine so that is absolutely correct guys now over here there is an example so we have three columns and two rows which we have converted to two columns and three rows now let me show you that practically how you can do it in a variable and I'm going to start a numpy array and I'll have two elements in that my first element will be 1 comma 2 comma 3 comma 4 and my other element will be say 3A 4 comma 5 comma 6 so I have a two dimensional array that contains two rows and four columns now I can convert that to four rows and two columns let me show you how to do that you're just going to type in a is equal to a do reshape and I want to convert it to say four rows and two columns go ahead and print this so it has convered that to four rows and two columns as you can see in front of your screen now let me show you that earlier this is not the case I'm going to type in a print statement here as well in order to show you that how it has reshaped so earlier we had four columns as well as two rows but now we have two columns and four rows so this is how you can perform the reshape operation now let us talk about slicing so slicing is basically extracting particular set of elements from your array and the slicing operation that happens there is pretty much similar to the one which is there in list as well so suppose if I want only this particular element that is three so for that what I need to print I'll show you print a and the index value of three which is present at zero comma and the index is two let me tell you how indexing happened so this element will be zero this element will be one now if I want three from here the from the zeroth element I I want the index two indexing starts from 0 1 and two so that's why I've written 0 comma 2 and it should print three for me let us see if it does that or not and yep it prints three now say if I want to print four and six now for that what I need to do is I need to remove this two here and I'm going to put a colon that says all the rows including zero and in that row I want only index three so we have only two rows so if I would have written zero colon one then it wouldn't have included this particular row so if I have one more element here so I can actually write here two so that would actually include the element which is present at the second index so when I say zero colon this actually means all the rows that include zero as well so we have only two rows it will include both the rows and at the same time it actually going to print the third index from both of these rows so let me show you if it that happens or not and yep it happens we have four and six available with us now just to remove confusion what I'm going to do is I'm going to add one more element and I'm going to give values to it say 7 8 9 and 10 so now if I want four and six I can't just write zero colon because if I do that it'll print 10 as well let me show you that yep it has printed 10 now in order to avoid that what I can do is I can write in here two so as I've told you this is the zeroth element first element and the second element so when I write 0 col 2 it won't include the second element it'll only include zero as well as the first element now inside that we have index three from both of these rows that is why we'll actually get four and six let us see if that happens or not and you can see four and six is now available so this is how you can perform slicing when we in numpy arrays now what I'm going to do is I'm going to type in a equal to np. line space and now over here first I'll write one comma say three and I want say five values between 1 comma three what this will do is it'll actually print the five values which are equally spaced between 1 to three so let me print this first I'm going to type in print a and go ahead execute this and you can see that we have one then we have 1.5 then we have two 2.5 as well as three so if I would have written here 10 it will actually give me 10 values between 1 to three and yep you can see we have the 10 values between 1 to three so this is how you can perform line spacing as well so we saw how to perform reshaping and slicing now let us see what are the other operations so we are now going to find out the minimum maximum as well as the sum of our numpy adday so let us go ahead and execute that practically let me remove all of this and now I'm going to Define one more numpy np. array and I want elements in let's say 1 2 3 now if I want to find the element which has the maximum value so what I can do is I can just type in here here print a. Max that's all and it'll give me the maximum value in my a numpy array which is three obviously if I want to find minimum value so I'm going just going to type in here Min and it'll print the same for me which is one now if I want to calculate sum it is pretty easy just go on and type sum and it'll give you the sum that's all guys it's that simple whatever I'm telling you these are all the basics that you require after that whatever your requirement is there on that basis you need to use those basic knowledge that you have and implement it now the best way to do that now the best way to understand any programming language is to play around with it so you know the basics with the help of those Basics just install py Cham first then try out new things like how should I get that how should I get this and if I'm not getting it what is the reason behind it so go on and try to discover new new things so the conclusion is you need to actually perform things practically you need to make sure that you're not only getting the theoretical knowledge you need to perform it practically that's why I always say that side by side when I'm executing these practical you need to do that as well although you might find it pretty basic but with the help of this knowledge you can perform a lot bigger task as well all right so Janice looks happy now so let us move forward with our slides so now comes the axis concept here guys it is pretty similar we have a numpy array which looks like this and the rows are called axis one and columns are called axis zero now you must be thinking what is the use of this axis suppose if you want to calculate the sum of all the rows then you can actually use these axis and you can do that now let me show you practically how it happens I'm going to open my py charm again and I'm going to show it to you let me remove this and let me add one more element here 3 comma 4 comma 5 all right so if I want to find the sum of axis zero it's very very easy just go on and type print a do and type in AIS equal to0 go ahead and print this and you can see 4 six and 8 1 + 3 is 4 2 + 4 is 6 similarly 3 + 5 is 8 if I make this as XIs one and print this so it gives me 6 and 12 because 3 + 2 + 1 is 6 similarly 4 + 5 + 3 is 12 so this is pretty easy I know now let us go back to our slides and see what what are the other operations so there are many mathematical functions that you can perform with numpy that is to find the square root of each element you can even find the standard deviation so these two operations can be performed with the help of numpy you can find the square root you can find the standard deviation now let me show you that how you can do it this is my pie charm again so now I'm going to remove this print statement here and I want to print the square root of each of the elements that are there in my numpy array which is actually assigned to variable a so I'm going to type in here print NP do sqrt that is square root of my npy r a go ahead and execute this and it is actually printed the square root of each of the elements the square root of one is one for two it is 1.414 for three it is 1.73 again for three it is 1.73 then for four it is two then for five it is 2.23 this is how you can find the square root of each of the element now when I talk about standard deviation so you can find that by typing here so now if I want to find the standard deviation what I need to do is instead of sqrt I'll just type in here STD and it'll give me the standard deviation that is how much each element varies from the mean value of my numpy array and this is the standard deviation guys it's that simple so this is how you find standard deviation now let us go back to our slides and see what are the other operations that are still left now these are the basic mathematical functions that you can perform with numpy arrays like addition multiplication subtraction and Division and that will actually happen element wise so basically you are performing Matrix addition matrix multiplication Matrix division as well as Matrix subtraction let me go ahead and show it to you practically it is very very simple guys so similarly I'm going to Define one more array and let me name it as B let me remove this print statement now if I want to calculate the sum so what I need to do is I need to type in print A+ P that's all you need to do but when I talk about list again I'm telling you that when I talk about list if I do that it'll concatenate both the list so if I want to print list that is the addition of two lists I need to use for Loop so that is where numpy aray stands apart and it is pretty convenient go ahead and execute this and you'll see that element wise addition has happened one + 1 is 2 2 + 2 is 4 3 + 3 is 6 similarly 3 + 3 is 6 then 4 + 4 is 8 5 + 5 is 10 all right so this is how you can perform addition you can perform subtraction by using the subtraction operator go ahead execute this and you'll find all zeros because 1 - 1 2 - 2 3 - 3 3 - 3 4 - 4 5 - 5 will be zero only right no rocket science now go ahead and multiply it as well and see what happens so you have 1 into 1 is 1 2 into 2 is is 4 3 into 3 is 9 again 3 into 3 is 9 4 into 4 is 16 5 into 5 is 25 if I go ahead and divide this it'll give me all ones and yep it does so this is how you can actually perform addition subtraction multiplication and division using a numpy arrays now let me go back to my slides and see what are the other operations present so now guys let me tell you one more thing if I actually want to concatenate two arrays I don't just want to add those two arrays you can say that if my one array is a box then and I want another array on top of it so let me show you how you can do that actually there are two ways to do that one is called vertical stacking and another is called horizontal stacking let me show it to you one by one first I'm going to show you vertical stacking for that what I need to do is print np. vstack and a comma B let us see what happens when I run this so we have 1 2 3 3 4 5 then again we have 1 2 3 and 345 so this is called vertical stacking if I want that horizontally I'll just write in here Ed stack and I'm going to run this now and you can see that we have 1 2 3 then again 1 2 3 that means these two are present added horizontally and we have 3 4 five again we have 3 4 five so this is how you can perform stacking as well now there's one more thing that I want to show you if I actually want to convert this particular num py array that is a to say a single column so how I can do that just type in here print a do Revel that's all you have to do go ahead and execute this so you have one 2 3 3 4 5 so we have 1 2 3 3 4 5 let me go back to my slides and see what are the other topics that we are going to cover now come certain numpy special functions now I'm going to talk about s function and cosine function first so what I'm going to do is I'm going to use this cosine and sign function and I'm going to plot s and a cosine graph so for that I'm going to import a module called matplot Li so you don't need to worry about that module because I'm going to discuss about matplot lib in the upcoming sessions so there'll be a detailed session especially on Mt plot Li so you don't need to worry about what exactly mat plot lab is and how it works and all those things because that'll be covered in the upcoming session for now what we are going to do we are just going to use S and cosine function in order to print their graph so for that I'll open my py charm and let me remove this and import M plot lip do pyplot as PLT now we are going to Define two coordinates that is X and Y first X is equal to np. AR range 0 comma 3 into np. Pi comma 0.1 uh now I'm going to define y so for that I'll type y NP dot sin x now I'm going to use PLT in order to plot the graph x comma y now finally show the plot for that I'll type plot. show you must plot. show to make a graphics appear so plot. show and here we go go ahead and execute this and you might be able to see a graph and yep it is here similarly what if I change the sign to cos and should give me the cosine graph go ahead and run this and you can see we have a cosine graph as well similarly if I write in here tan that is any other trigonometric function and I print this so I get the graph for Tan as well so I'll open my presentation once more and we are going to see what are the other special functions that we can use with numpy now numpy comes with two very good functionalities I would say that is called exponential function and logarithmic functions now expon IAL this e value is somewhere equal 2.7 and we all know log so when I talk about log it is actually log based 10 and when I'm talking about natural log that is log base E I will write it as Ln so instead of that I've written log that means log base 10 so you can perform these operations with the help of numpy let me show you how you can do that so I'll open my py charm let me remove this and I'm going to define a numpy array let it be ar equal to np. array 1A 2 comma 3 now I want to calculate the exponential value I'm going to throw in a print statement and I'm going to write in here np. exp a and this will calculate the exponential value for me and let us see if it does that or not so yep as I've told you earlier as well value of e is 2.71 so e to the^ of 1 is actually equal to e so it has returned the E value but e to the power of two will be somewhere equal to 7.38 e to the power of 3 will be somewhere equal to 20.85% all right so when I talk about one so e to the^ of 0 will be equal to one right so log or Ln AR equals to zero similarly the other values as well now if I want log base 10 instead of Ln or you can say natural log I can just write in 10 and go ahead execute this and you'll find log base 10 values so obviously when answer is one that means anything to the^ of 0 is equal to one so the answer will be zero here and similarly we have other answers as well if you are pretty if you're unsure about it you can open your calculators and do that let's take up another question which of the following can be done with numpy arrays option A index option b sliced option C iterated or option D all of the above so if you know the answer please leave it in the comment section below you have learned about numpy so let's move on to python pandas in this section you will discover how to manipulate and analyze data using this versatile Library so pandas is a python Library which is used for data manipulation analysis and cleaning and python pandas is well suited for different kinds of data such as we can work on table data with heterogeneously typed columns we can work on ordered and unordered time series data arbitrary Matrix data with rows and column labels we can work on unlabeled data and we can also work on any other form of observational or statistical data sets now I'm going to tell you how you can install pandas on your systems guys it's very easy to install python pandas you just go to your command line or terminal and just type pip install pandas or if you're working on an IDE such as pycharm you can just simply type in PIP install pandas in your terminal over there or you can just open the project interpreter and add the library over there since we going to work on Jupiter notebook I'm going to tell you how you can install python pandas on Anaconda so you just have to do one thing so I'll just show you guys how you install python Pand on your system you open the Anaconda prompt we'll wait for the prompt to set up so you type cond install it's already there in my system because I have already installed pandas since I have already worked on various data analysis projects and it's a very integral part of it because to work on a data set to read a data set you require pandas and it's just that you cannot work without pandas if you are working with any data related project so this is how important python pandas actually is I'm going to tell you a few applications of pandas as well so first of all you can just say that python pandas is an integral part of data whichever project you're working on so you can work on economics you can use Python pandas for stock prediction you can use it for recommendation systems then you can use it on neuroscience and statistics also you can use it for and then there is advertising so many data coming from different platforms you can just analyze the data using pandas you know clean the data for irrelevant you know inconsistencies in your data you can do that using pandas and then you can use it for analytics as well that's the very basic use of python pandas that I can think of so right now that we know how pandas actually is in Python Programming and what it is used for let's go ahead and take a look at the very integral part of pandas that is data frames and CDs we'll wait for this to install guys meanwhile I'll just tell you what are data frames and series guys so data frame is a twood dimensional and the size of the data frame is mutable potentially heterogeneous data or we can call it heterogeneous tabular data so the data structure which is data frame also contain labeled axis which is rows and columns and arithmetic operations align on both rows and column labels it can be Tau as a dictionary like container for series objects now what exactly is a series guys so a series or a panda series is a one-dimensional labeled array capable of holding data of any type which is integer can be string float python objects Etc and the access labels are collectively called index and Panda series is nothing but a column in an Excel sheet so let's just take a look at a few examples and then you'll be able to understand this better what I'm talking about like pandas and series what exactly they are we'll be working on a example now so I'll just take it to jupyter notebook guys so we have have already created a jupyter notebook if you are not familiar with jupyter notebook guys we have a full tutorial on how to use jupyter notebook all the cheat sheet and everything so you can just refer to those in our adeda YouTube channel and make sure you subscribe to Eda for more exciting tutorials because we have a lot of content on python guys so if you want to Learn Python inside out or any other technology for that matter we have lot of content on YouTube you can refer also if you are added be sure to check out our courses on ed. and we have a full python programm certification program that you should also check out so since I have already installed python pandas I'm just going to import pandas as PD run this I'm not going to face any problem running this command because I have already installed pandas okay so what this command will do over here it's going to install the package the latest release of pandas for me I think that's why it's not running okay we have our first statement over here and we have successfully imported pandas as PD so I'm using the alas as PD I hope you guys know what alas is so let's just say I'm importing this Library so alas is going to be this one that is PD so for importing I'll tell you why I'm using this now if I want to create a data frame I'll just use DF as my variable name for data frame so I'm going to use the alas now when I type tab over here okay I'll just so this is how I can use my alas to create a data frame so this is just to tell you how you use an alas now I'm going to show you how you can create a series and a data frame so first I'm going to okay I'll have to import numi as well because I'm going to use it to create a null value all right so DF is equal to I'm going to make a series so I'll just write it as s all right series and I'm going to pass a list of values let's say 1 2 3 4 5 six and I'm going to use my Numa Now to create a null value like 8 n and one more value let's say 10 so it's going to create a series now when I print s so we have a series which has indexes which are already there and all these values that I passed inside a list so this is how you create a series in Python guys using pandas after this I'm going to tell you how you create a data frame so for that also I'm going to tell you how you create a data frame using a dictionary object and how you can create a data frame using series as well so now what we are going to do is we are going to create a data frame by passing a numpy array with a daytime index and label columns so I'll take one variable let's say date or dates I'll just type it as d and I'm going to take PD dot so we're going to take the date range and after this I'm going to pass a few value let's say 2020 and I'm going to pass values like we're in the month of March so I'll just write it at March and after this I'm going to take periods which is equal to let's say 10 so this is my date range guys okay I have an invalid syntax right should work fine now so when I print D over here so I have all these values in our date range format after this what I'm going to do is I'm am going to take one data frame which I'm going to take as DF for obvious reasons to make it clearer and I'm going to take data frame and inside this I'm going to pass a few values so first of all I'm going to take a few random values so I'm going to use np. random dot random number and inside this I'm going to pass 10 let's say four now I'm going to get the index values as D and I'm going to have to pass a few more values which is columns so I'll pass the columns as a list and I'm going to take let's say four columns so I'm just going to take okay wait a minute a a b c D all right do we have any errors no so now I'm going to print my data frame so I have a data frame guys which I have created using you know passing an umpai array and I have a daytime index with labeled columns which are a b c and d this is my index guys and I have all these random values using NP ARR so this is how you create a data frame it's just a simple example and I'm going to show you how you can create a data frame by passing a dictionary of objects that can be you know converted into a series also so so I'll take let's say again DF is equal to pd. data frame and I'm going to pass a dictionary over here now so I'm going to take a few values first of all so first value is let's say a now after this I have to pass something right okay I'm going to write let's say a list of 1 2 3 and four after this my next value is going to be let's say B and I'm I'm going to pass a time stamp let's say and for time stamp I'm going to use same I have used over here 2020 03 01 I'll use the right and after this I'm going to pass one more value let's say C and I'm going to use a series now a series object and inside this I'm going to pass one and the index is going to be let's say range all right index is equal to a list with a range of four because we have only four values over here we don't want any null values and after this I have to type in the data type as well the data type of the series guys so for that I use D type is equal to let's say float 32 all right after this I provide my next value which is D now for D I'm going to use uh an nump array and for this I'm going to pass a value let's say not three let's say five multiplied by four and let's take the D type is equal to integer 32 yes all right now I take my final value which is going to be e and inside this I'm going to pass a a data frame or we're going to use the categorical object guys we're going to talk about this later on in the session so don't worry I'm just showing you how you can create a data frame using all these objects that we have at our disposal guys instead of test and train we can just call it as true or false doesn't matter we are taking categorical object so it has to be either true or false or it can be zero or one but it has to be decisive in a way that there are only two values so I take another value and for this let's just say I give the value Eda all right so our dictionary is done over here so we have created our data frame guys there's no error now when I print this so we have our data frame guys so A B C D E and F so we have all these values using different data types or we can call it objects as well so for that also we can check the data frame and we just write D types and it's going to give us all the data types that we have so we have date time stamps over here integer float integer category and an object because I have used a string over here that's why it is giving us an object but in the new release that is python 1.0.0 it's not going to be an object it's going to show you it is a string so don't worry guys and we have already made a video on python pandas 1.0.0 with all the features that have come with the new release the new stable release released last month you can check that out as well to check for the new features that we have come across so now that we have done this let us take a look at the next topic that we have which is how to view data so viewing data is basically you know how you actually look at the data or how you going to look at the data using Panda's Library so we'll just jump right to jupyter notebook guys and I'll tell you what kind of functions or all those things you have at our Bay that we can use to view our data so we'll do one thing first of all we have data frames already that we have over here so I'll do one thing I'll just change it to df1 so that we have different data types or I'm sorry different data frames guys I'll run this this and this as well when I check for DF dot d types should be different guys because we have already made a data frame using that all right it's not so I'll run all the wait so I'll do one thing I'll restart and run all the cells so that we have two different data frames so first of all the first very basic thing that you can do for your data frame is to use I'll just tell you guys you write DF do head so what this function is going to do is give you the first five values inside your data frame or the first five rows and similarly for the last rows you can use the tail method so this is how you get the first and last values inside your data frame so it's going to display all the five values that you have at your beginning and the end of your data set after this we have DF do index so what this will do is it will give you all the values from your index and similarly we have DF do columns which is going to give you all the columns from your data frame so this is how you view your data guys and then we have data frame. two numpy which is going to give you an nump representation of the data so I'll just tell you how you can do that so I'll just write DF do2 numpy wait a second guys yes so I'm going to create a NP array using this this I actually created an npire array and for dfr data frame of all floating Point values data frame. 2 numpy is actually fast and does not require copying the data so it is a very best deal for we have and then okay I'll just remove this I don't want this and then we have data frame. describe which is going to give you somewhat like this which is going to give you the count the mean the standard deviation minimum 25% 50% 70% and maximum so these all values using the describe you can have which is going to give you an idea or a perspective of how your data actually is and what kind of calculations are already there that you can think of then we have sorting by an axis we can sort our data using an axis so for that you have to just write okay I'll just show you guys you just have to write DF do sort by index and inside this you you have to give the value of the axis I'll just give one and then let's say ascending you want it to be ascending no I'll just write it as false so it has given me the data frame by sorting the index similarly I can sort it by The Columns as well or I'm sorry sorted by values so I'll write as values and I want to give the value as say values and I'm going to give the value as let's say by I want to sort it by C it has sorted the values depending on C so this is how you sort your data frame guys and now that we know how we can actually look at our data I'm going to tell you how you select particular values inside your data guys I'm going to show you how you select a single column from your data frame so we write DF it's very simple guys to get a value from your data frame using only a single column you can write a or let's say C it's going to give all the values from C over here it has actually given you frequency it has given you name data type as well so this is how you actually get a single column from your data frame now let me show you how you can slice the rows as well so for that we going to use the slicing if you have actually worked on list comprehensions so we have slicing the data over here we are going to follow the same principle here as well so I'll just write DF now I want my first starting from my first value to third value so it has given me only three rows starting from the zero row and it has given me third row and it does not actually include the third row because it starts from zero so I'm giving three values if I write six over here I'm going to get the sixth value but it's not going to be at the sixth row because the first row over here is going to be zero row I hope you understand this guys so I have shown you how you can slice your data you know to get particular number of rows now let me tell you how you can uh select the data using the labels guys so for that you have to use DF dot there has to be location L and inside this you're going to pass the values by labels guys all right so let's pass D that is n0 so let's see what the output is guys all right so we have got all the values using the label that is D here which we have passed over there in our previous section where we have declared the data frame and I'm sure this is visible to you guys now the next thing is uh selecting data on a multi-axis by label so what we'll do is we'll write df.loc and after this we write hyphen and we have going to create let's say a and we're going to pass C right so it's going to give me the values accordingly which I passed over here so instead of a I can write b or I can write D so this is how you can select multiaxis using labels guys and I have written this over here so I can just write let's say 0 to 3 Let's see what happens or we have an error guys you cannot do this so we'll now move on to the next topic that we have is showing label slicing both end points are actually included so how do we do that so instead of this we can just let's say copy this paste it over here and copy this base over here remove this so this is just to show you guys how you can work with it I'm very certain that the data that you work on is not going to be like this it's going to be very complicated so this is just to give you a perspective as a beginner how you can work with pandas now I'm going to tell you how you can reduce the dimensions of the returned object as well so for that you just type one thing guys remove all this get just one value and this is going to give you the column number at over there and this is how you get the values inside a data frame so moving on let's say we want to get a Scala value so for that we just write okay let's say d0 right let's see if it works we're getting the same values guys only from the zero through for getting the fast access to a scaler you can just write as uh DF instead of Lo we can just write at okay we have an error guys I'll just remove this and let's see if it works yes so I'm getting the exact value at the zero row at the column number c now I'm going to tell you how you select a value from using the position inside your data frame so for that we use DF do I all right so let's say three okay so I'm getting the all the values from third column and similarly we can slice the data you know you can just get it like 3 to five right and we can add more values to this like 0o to two so this is how you select the values from your data frame guys now we have Boolean indexing as well inside our data frames so I'll just tell you quickly what it is so for that you just write DF now I'm going to check if DF column number a let's say this is interesting guys so it has given me all the values inside a where a is greater than zero if I write here let's say two I have no values because none of the values are greater than two so this is how you can get the Boolean indexing this is actually important when you applying functions to your data frame guys so Moving On Let's uh take a look at and another method which is is in method I'll just tell you how it works guys so it's basically us to check if the particular value inside your data frame is in there or not now there's one more thing we can set new values inside our data frame we can set a new column which automatically aligns the data by the indexes so for that we can make the series and we can set the values by label we can set the values by position and we can set the assigning with a nump array as well and the result of the settings will actually align with the data frame where a new operation with the setting can be followed where you can simply align the data frame with the existing data frame now let's go ahead and take a look at the next topic that we have which is handling the missing data inside your data frame so let's jump right to it guys we'll go to jupyter notebook and we'll work with our missing values now so pandas Prim use the value np.nan to represent missing data It Is by default not included in the competitions and we're going to see the missing value right now so first of all you have to reindex I mean you have to do reindexing which is going to allow you to change add delete the index on a specified axis so which is going to return a copy of the data as well all right I'll just take df2 is equal to DF do reindex so this is how I'm going to do the reindexing guys so index is equal to let's say d 0 to 4 yes I'm going to get the columns after the re indexing is going to be equal to list of DF do columns and I'm going to add one more column which is going to be let's say e all right now what I'm going to do is I'll do LC I'm going to check a few values so instead of dates I've taken D guys so D of 0 and D of 1 at e equal to 1 now let's check what is df2 is we have two null values over here so this is how I'm going to show you how to handle missing values inside your data frame so we have done re-indexing so first of all I'm going to check for null values so we have true over here and we can get the count as well is null and we count these null values all right right now we're going to drop a few columns so we're going to drop the na that is the na values so as you can see from our data frame all the values that had null values are dropped actually the whole column has been dropped or we can do one thing fill in the missing data guys just do one thing okay check df2 we have so we can do one thing we can fill the missing values and we going to provide some value let's say value is equal to 2 right so we have actually filled the value with some of the value wherever there is a missing value we have given a value value that is going to fill over there so this is how you get or you know check for all these uh missing values inside your data frame after this you can actually get a Boolean mask where values are NN which is null so for that you do PD dot okay is na df2 so this is going to get you a Boolean mask which I've already told you how you can check using DF do is null same thing but different processes to run this now let us move ahead and to the next topic that we have which is Panda's operations guys Panda operations are nothing but a few operations that you can apply on the data frame or any other pandas object so we have descriptive statistics that we can apply we can apply functions histogramming is there and string Methods is also there so I'll tell you what histogramming is when we are talking about it so let's take it up to jupter notebook again guys I tell you how you can actually work with Panda's operations so first of all I'm going to tell you a basic operation which is that is a descriptive statistics so it's going to give us all the mean values similarly we can get one value like DF do mean provide one value over there so this is how you get it guys or we can write it as two right all right so this is how operating with objects that have different dimensionality and need alignment in addition P automatically broadcast along the specified d Dimension so for that let's make a series I'll tell you just how it works PD do series uh give it a few Valu let's say 1 2 3 NP do Nan 5 I'm sorry four five and then give the index value index is going to be dates and let's just shift all this two places right we have made an error guys length of pass value is six and index implies 10 so we have to uh actually put more values so WR 6 789 yes now when I print s over here we have all these values now we can do one more thing so we write it as DF do sub and we pass the S over here which is our series and we make an axis write it as index so we have operated with objects that have different dimensionality and needed alignment so in addition pandas actually helped us automatically broadcast the specified Dimension so now I'm going to talk about applying functions to the data so we already have data frame let's see what we have so we have this data frame guys so what what I'm going to do is I'm going to apply a few functions so first of all I'm going to use the apply method over here and let's see what all do I have let's just check we have absolute absolute UT all all close a Max a minimum angle any append all these functions that I can apply on this so let's say we have comum let's see what this does guys all right so this is how it works now let's apply a few more functions guys so I'll write Lambda X so we are talking about Lambda functions here I'm sure most of you must be aware of the Lambda functions that we have in Python if you don't have any prior knowledge on Lambda function guys there is a full tutorial on how Lambda function Works in Python guys so this is how we applied Lambda function to get the subtraction between the X Max and X minimum right for all the columns we have subtraction between all these values so this is how we apply functions to our data guys now I'm going to talk about histogramming so histogram is a representation of the distribution of data so this function we have which is map li. pipot doist on each series in the data frame resulting in one histogram per column so what we'll do is we'll make a series and it's going to give us value counts for histogramming how do we do that actually so we can just write s do value counts right let's see if it works right we have one value for each so this is how we get or do the histogramming with our data guys now I'm going to talk about the string method so series actually is equiped with string processing methods in the string attribute that actually makes it easy to operate on each element of the array so let's just move ahead with the example so I'll make a series guys PD dot let's say series and inside this I'm going to pass a few string values so I'm going to start with ED Rea write python next let's write Jupiter give a few null values as well to make it a little or slightly different from perfect all right so give it a few value let's say football and looking at the current scenario let's write w so we have a series over here guys now what we'll do we'll take or use the string Methods so I'm going to make it all to to lower which are already lower so I'll make it to Upper guys upper letter words so everything we have changed using the string Methods inside our SE uh pandas series these are all the operations that you can perform on pandas guys so let's move ahead to the next topic that we have which is merging so in merging we are basically going to merge two data frames together so we have two functions which is concat and join so concat Panda's objects along particular axis with optional set logic along the other axis it can also add a layer of hierarchical indexing on the concatenation axis which may be useful if the labels are the same or overlapping on the past axis number so let's take a look at the example for this so we have our data frame I'm going to use PD do data frame give it a few values let's say and B do random dot random number from let's say 10 and four all right so we have all these values now what I'll do is I'll break it into the pieces so how to do that so let's say I write it as df2 is equal to DF from first to Third third row the next one is DF from third to let's say seventh row and then we have DF from 7th to the end of the data so this is how I am going to break into the pieces now when I write it as df2 we have three data sets now I'm going to right now I'm going to use the concatenation function using concat all right I'm going to concatenate df2 so this is how I have concatenated the missing pieces not the missing pieces the several other pieces together using the pandas concat function now let's talk about the join function that we have so for this basically I'm going to tell you how you can uh do the left and right join so for the left join I'll write left is equal to PD do data frame and let's see first value let's say a give it a few values let's say 1 2 and then say B we have 3 4 all right we make the for the right as well so I'm just going to copy copy all this paste it over here okay I'm just going to write it as D this is going to be let's say C and change a few values so we have left and right and I'm going to just type left and then we get the output for right so I'm going to join all these two using the join function so for that I'm going to use the merge function and inside this let's say left we have right and on is equal to I'm going to join it at uh let's say a let's see how it works okay it doesn't so we have a key error which is a so I'll change it to a guys so we actually join using the merge function over here and another example that I can think of is uh let's say you have left and right we can change the values differently and we can just group them together now what I'm going to talk about is grouping guys so how you do the grouping of different data inside your data frame using pandas first of all for that you have to split the data into groups based on some criteria that you have have and then after that you apply some functions on them and then later on you can combine the results into a data structure so first of all you have to get a data frame guys so let's see we have a data frame over here so we can actually group it by let's say right I'll just write Group by say a and just going to sum right we have an error guys so we have a key error that is a because we don't have over there so I'll write it as let's say two all right we don't have two as well we have a key Arrow we don't have two over there because it's not an string value it's an integer value so we have our values right over here so we have grouped the data using the column that is number two now we can actually group the data by multiple columns and form a hierarchal index so for that I'll just copy this guys or over here only I'll just do one thing two and let's say three so this is how you actually combine multiple columns to form a hierarchial index but here again we don't have actually categorical values for these columns if we had we'd be able to do that you know if we had like let's say true and false it is going to have created a hierarchal index which will have different values for True columns and for false columns so that's how you do the grouping or that's where you actually need grouping using pandas now let's move ahead and take a look at the next topic that we have okay we have already talked about operations then I have talked about merge where we have talked about concat and join and then I've talked about splitting the data how you apply the functions and then combining the results together merging we have talked about grouping now I'm going to talk about stack and pivot table so what exactly is a stack guys in pandas I'm sure most of you must have heard about some other definitions of Stack so I'm going to tell you about this with perspective of band's Library here so the stack function is used to stack the Pres Skype levels from columns to index and it returns a reshaped data frame or a series having a multi-level index with one or more new innermost levels compared to the current data frame so you're going to understand this with an example so I'm just going to take a say my topple is equal to I'm just going to take a list and inside this let's see we have values and we provide or we get two lists over here a list inside a list guys so let's take a few values take 1 2 3 4 5 and then again let's say 6 7 8 9 and 10 or we'll add few more values guys let's say 11 12 and 13 over here I will add few more values let's say 17 18 and 19 so we have our to I'm going to create one more variable index so we'll have multi-index so from tles and inside this I'm going to pass my tle pass the names as well so the names are going to be let's say first and and second so we have our index now I'm going to create the data frame guys so for this we write PD do data frame and inside this I'm going to pass a few values NP do let's say random do [Music] random number so we have eight values and two columns all right so and the index is going to be index and columns is equal to A and B all right we have an attribute a guys I made a mistake so there's no error now and I'm going to make one more data frame so inside this I'm going to pass this value now I check my data frame so I have re shaped my data frame with this first and the second and all these values now we're going to talk about the stack method guys so which compresses a level in the data frames columns so we're going to do one thing we're just going to do df2 dot stack right this an attribute Arrow so this is how we stack or compress a level in the data frames column guys and with a stack data frame or series having a multi-index as the index inverse operation of Stack is unstacked by which default it's going to unstack whatever you have done with using stack so we'll do df2 Dot unstack and this is how you unstack now we'll talk about the pivot tables guys oh wait let's put it inside uh variable let's say a all right so this is how you unstack guys we getting different values there now we're going to talk about the pivot tables that we have in pandas so it is nothing but the levels in the PIV table will be stored in multi-index objects on the index are columns of the result data frame so we'll take a look at one example guys which is going to be pretty clear so we'll take DF again PD do data frame and inside this we're going to take a few values or we're going to take a list inside a dictionary so let's go with a few values say one or let's say a all right we write a b c d we moove a few values over here multiply to three now we take another value which is going to be B and for this we're going to take a list again so let's say multiply to four take another value let's say C now and inside this uh we're going to pass a few values again so we're going to pass Six values so let's write p p and p q q and Q multiply to two because we want number to be 12 and now D is going to be np. random dot random number and the number we want is 12 and we take one more value e and we take the same values for this as well random do random number 12 no errors I guess so we have an invalid syntax guys so we forgot to add a comma over here and here and here right so I think it should work fine now without any errors so we have printed the data frame over here guys so this is how it looks now we can produce pivot tables from this data very easily guys the very reason of creating this data frame was to get the pivot tables now what I'll do is I'll just write PD dot pivot t table and I'm going to pass DF over here wa DF and the values is going to be let's say d and index is equal to a and b and columns let's say is equal to C so this is is how you create a pivot table guys now that we done with pivot tables uh let me talk about the next topic that we have which is time series and categorical so we have done reshaping merging grouping as well now we going to talk about the time series and categoricals so pandas has simple powerful and efficient functionality for performing resampling operations during a frequency conversion which is for example converting secondly uh data into five minutely data and this is extremely common but not limited to financial applications so we're going to take a look at a few examples and for categorical data data that you collect can be either categorical or numerical so numbers often don't make sense unless you assign meaning to those numbers so for categorical data is when numbers are collected in groups or categories and categorical data is also the data that is collected in an either or yes or no situation for example we have zero or one we have true or false so that's going to be the category over there so let's take a look at a few examples to understand this guys the time series and categoricals so we'll take a look at a few examples for time series so first of all what I'm going to do is I am going to make a Time series guys so first of all what we'll do is we'll convert the data into five minutely data so it's very common guys so I'll just take the range first of all so we'll take the dates all right I made a mistake just cut this so I'll just run this again we'll get one more column and now what I'll do is I'll make one variable using the pd. DAT range yes and I'm going to provide the range as let's say 2020 01 or 03 01 we want the periods is equal to 100 and let's say frequency is equal to S all right let's print dates okay so we have dates over here just remove this for now so now we take one more variable let's say DS is equal to PD do I'm going to take a Time series and inside this I'm going to use NP do random and random integer which is going to be 0 to 500 and the length is of dates and then we have index is equal to dates so we have okay we have number attribute no random randant all right so we have an unsupported date time so I'm going to have to change this over here so we'll write it as let's say 3 1 or we going write 33 220 right so let's see if it works now doesn't so we getting the unsupport D type okay so we just mention a few more stuff over here so we write it as 0 0 0 0 so I think I figured out the problem over here so I've changed this to the this format and now I'm going to add one more parenthesis here and remove this one and now I'm not getting any errors guys so I'll run it again right so now what I have to do is I will have to make a few changes to the TS which is time series I've made so I'll write it as ts. resample and I want to make it to 5 minutes right and I have to sum this so no errors there guys so now I'm going to do the time zone representation so for that I'm going to get one more okay I'll just copy this guys this little change to this only so I'll just copy this paste it over here and here I have to make a few changes that is 0 0 rest everything is going to be fine and we change this to five all right so now we make another time samp and we just use PD do Cs and inside this I'm going to use NP do random dot random number and the random number is going to be the length of dates and dates over here all right so now when I print Tim stamp I'm getting the output as some write this so this is how you get the time zone representation guys you're getting the date the time and everything and the data type is float 64 and then you can also get the UTC as well so for that I'll just write TS UT TC and we just write timestamp do TZ localize and we get UTC right it's UTC now I'm going to print this so we get the UTC as well so this is how you create the time zone representation and now after this I want to show you how we can convert to another time zone so for that we don't have to do anything we just write TS dot all right TS UTC do TZ which is time zone convert and we write us eone so we have converted into the US time zone and converting between time span representations also we can do that let's just say that's your exercise so you have to convert between the time spans representations so that you'll be able to understand this better for that you have you don't have to do anything you just have to take the date range the periods is going to be five and then you write the frequency instead of s you write it as M the rest all is going to be the same guys okay I'll just do it here as well just copy this paste it over here instead of s it's going to be M we have to remove this all right now I make the Tim stamp is going to be the same guys now print the time stamp this is how we convert or after this we take one more variable let's say PS and I'm going to to period all right now when I print PS over here this is the output I get so the frequency is m i have changed the frequency and now I can just convert it to time stamp guys let see where it is this is how you create it into a time stamp now converting between period and time stamp enable some convenient arithmetic functions to be used so for that we have period range and all those things that you can add now moving on to the next topic that is categoricals so for that let me just take one more data frame guys so I'll write it as DF is equal to PD do data frame now I'm going to take a few values inside this uh dictionary the first is going to be let's say ID and now I'm going to pass a list with a few values precisely six so I'm going to use six values over here now my next topic is or the next key is let's say raw grade or just grade we'll write so we're going to write a b c let's say again the guy is getting B and this one's getting a so we have five and one more let's say one guy has failed so we have our data frame let's print this okay so we have our data frame what I'm going to do is I am going to get the grade right [Music] so we'll get the grade is equal to DF grade now this is going to be the category I'm going to make all right now we print DF grade so we have grades like a b c b a e now I'm going to rename the categories to more meaningful names so what I'll do is I'll make the change over here only so I'll write cat Dot categories and I'm going to write the categories as let's say good instead of pass fair I'm just going to write very good and then there is excellent all right so we have very good very bad and excellent all right we have arrow guys there's something we have done so we have new categories needs to have the same number of items as the old categories so how many categories do we have over there let's just copy this so we have categories four so we're going to have to make four categories guys so I'm just going to add good as well there shouldn't be any errors now what I'll do is I'll just set the categories so I'm going to set the categories now let's say here I'm going to have to give uh six values guys so right very good let's say bad very bad medium good very good any sort of categories I have to give over here so I'll just write very bad good and let's say medium all right so after this I have set the categor as well now I'll just write DF great okay so we have good very bad then we have very good very bad and good and then we have n because we have not given any other category for that and we have the fire objects so we are getting very good bad very bad good medium so that's how you use the categoricals in pandas guys now I'm going to talk about plotting using pandas so that's going to be very simple guys for that I'm going to have to import one more library that is m plot lib dot pip plot I want to use it as PLT all right same thing goes with this as well all right this is going to be P plot right so there should not be any errors now okay so I will close all now I'm going to make one series guys and inside the series I'm going to provide a few random values like NP dot random do random number until let's say th000 or let's say 500 or yes 500 and the index is equal to PD do date range I'm going to take the date range as 1 3 2020 and let's take the periods is equal to 1,000 wait we have to take it as 500 because we have 500 values over there I hope no errors yes now I'm going to take the time stamp and we're going to get the come sum all right now ts. plot so we have a plot over here using pandas guys this is how we have created one uh series using the random numbers from numi library and using the P plot we have plotted a graph for random values which we have taken from 0 to 500 and the random range as well so this is how you take uh or get a plot using pandas guys now last but not the least we have another topic which is reading and writing to files so inside this I'm going to show you how you can read from a file and how you can actually create a file over there so we have our data frame guys or we have our TS this this is our TS guys so I can just you know convert it to a CSV file guys make it or give it a file name as let's say ts. CSV and it's going to save the ts. CSV file somewhere in my directory and similarly I can read from a CSV file so for that I can just write pd. read CSV and I'm going to have to give the file location for that so I'll just copy one file location from one of my data sets so this is one data set that I have so I'm going to check for the properties or wait I'm going to copy this paste it over here okay we have an uni code error so I'll just write over here and I'm able to read from the CSV file guys look at this instead of CSV I can write Excel and it's going to create a Excel file or a CSV file it's going to read from so that's how we actually read and write from files like a CSV file which is a comma separated file basically or we read from a file let's take up another question how do you import the pandas library in Python option A import pandas as PD option b from pandas import Haster option C import PD from pandas or option D import pandas so if you know the answers please leave it in the comment section below with an understanding of pandas the next step is python mat plot lip you will learn how to create visualizations and plot to represent your data graphically now it is very important for us to understand as to how matl Li Works fundamentally now it is pretty easy and pretty basic you have some data then your computer will draw that data to a canvas of some sort but it is only in the computer's memory now once your computer has drawn that data you can show that data so this is so the computer can first draw everything and then perform the more laborous task of showing it on the screen very basic I know you might find it pretty lame but it is very important for us to understand how fundament mat LLY BS so you have an example in front of your screen so again we have that data in which we have country-wise percentage of unemployed Youth and I've done some analysis and I've shown it graphically the percentage change in the unemployed youth country-wise between 2010 to 2011 so this is how that plot looks like it is nothing but a bar plot now there are various types of plots available we'll have a look at few of those in the next slide so we'll move forward and see what are the various types of plots so I've listed listed down six types of plots first is the bar graph then histograms scatter plot P plot hexagonal bin plot and area plot we are going to plot all these things in today's session with the help of mat plot lib module so we'll move forward and we'll get started with it we'll write our first matplot lip code so here's the most basic code in order to generate one of the most simple graph so let me explain to you this code first of all what I've done I have imported pip plot from matplot La as PLT then I'll use this P plot in order to plot the graph in the canvas and then finally I'll use this PLT which is nothing but P plot in order to show what we have got all right so pretty basic guys so what I'll do I'll open my py charm and execute this practical all right so before I open my pie charm we have a question from Brian he's asking what are the tools that are used for data visualization all right so I'll tell you we have a lot of tools available ink nowadays we have Tablo we even use R python so for python you need to import the M plot La Library so there are many many tools available in the market right now so I hope this answers your question Brian all right so he says yes fine so I'll open my py Cham and I'll execute this practically so this is my py Cham guys so over here I'll first create a python file with py extension and I'm going to name name it as first code now over here I'll first import P plot from mat plot lip so for that I'll type from Matt plot lib import By plot as PLT now this PLT is pretty much similar to NP that we were using in numpy if you can recall so it is not mandatory to use PLT only you can use whatever you want but a lot of people use it as PLT and I'll keep it that way now next next step is to plot our graph to the canvas so for that what I'll do I'll type in PLT dotplot and I'll write in here my X and Y AIS values so for x- axis I'll keep it as 1 comma 2 comma three then for y axis I'm going to add values such as four five and one so this will plot our graph in the canvas now final step is to show that plot how we'll do that I'll just type in here PLT do show and we'll execute this and see what happens run first code and Yep this is how our first basic graph looks like so with three lines of code you have got this graph so we'll move forward and we'll see how to actually add title labels to our graph for that I'll open my slides once more so now of course there are some problems with our graph first of we have actually learned in school that we are supposed to put labels on each axis and we need to also add a title to our graph it actually doesn't make sense our graph doesn't make sense if there are no X and y- AIS labels and a title so you don't know what his axis you don't know what is x- Axis you don't know what is y axis and what is the graph about Plus in terms of programming it is very unlikely that you'll be actually filling in data to the PLT dotplot function now over here you can notice that we are actually filling in data like 1 2 3 4 5 1 instead you will be passing variables into it all right so it should be something like PLT do plot and you can say x comma y if you have defined variables X comma y all right so now let us show plotting variables as well as adding some descriptive labels and a good title how does that sound guys all right so I can see a lot of people are pretty excited so we'll move forward and see how to add title labels and plotting variables now the code is pretty much similar to the previous one but it has few extra Fields let me explain you that so of course I've imported P plot from matplot after that what I've done I've have defined two variables X and Y and I have certain values in it like 5 8 10 and 1266 you can put whatever values you want and this can even contain a data frame a panda's data frame that has a data set after that what I've done I've defined PLT do plot function in which I have X and Y instead of filling the data I'm putting in variables that actually contain data after that I've added a title which is info then y label which is nothing but y AIS and X label which is nothing but xaxis after that I need to show my plot so for that I've done PLT Dosh show and the result is there in front of your screen we have a title we have labels for x-axis and y axis now let me open my pycharm and execute this practically so before I open my py charm and execute this practically we have a question from sidhart he's asking X and Y contains list yeah X and Y actually contains list we have list of numbers 5 8 10 and in X variable and in y variable we have similarly 12 16 and six so I hope this answers your question sart all right so he says yes fine so I'll open my py charm and execute this practically now this is my py charm again guys so I'll remove till here and obviously I need P plot function from mat plot lip so now I will Define X and Y variable so in X it'll have a list of numbers say five 8 and 10 and now I'll Define one more variable y which again has list of numbers 12 16 and 6 12 16 and six yep now what is our next step guys can anyone answer me all right so I've got a correct answer from Theon he's saying a PLT do plot function which is absolutely correct so I'll write in here PLT dotplot and instead of filling in data I'll be passing variables all right and now our next step is to add title and X label as well as y label so in order to add title I will WR here PLT do title and the title of My Graph so I can just write here info and now I'm going to Define X and Y labels for that I'll type in PLT doy Lael and I'm going to name it as Y axis similarly for X label I'm going to do the same thing xaxis all right now finally I'll type in PLT Dosh show now go ahead and run this so you can see that we have a graph that contains the title info y AIS as a y Lael as well as x axis as the X label now I'll again open my slides and we'll see what next are we going to see so any questions or doubts still here guys you can ask me any questions so we have no questions so what I'll do I'll open my slides and we'll move forward now this graph is pretty much incomplete or ugly I would say because what if I want to change the width of this particular line what if I want to add some grid lines what if I want to change the color so all those things how will I do that don't worry the next slide will actually tell you the same how to add style to your graph so how to add style to your graph for that first thing that you need to do is import the style function from mat plot Li module after that you need to call it style. use ggplot so whatever plot that you want to use I'm using ggplot right now then again I've defined four variables X Y X2 and Y2 and all of these contains list of numbers again I'm telling you it can be a data frame as well which contains data set then what I've done again I have used PLT do plot function but over here apart from X and Y there are many other fields so don't get confused I'll explain it to you it's very very easy so this thing G actually tells me that the color of my line should be green then this is label so this label is not for your x axis or Y axis it is for your curve which is line one you can give whatever name you want then we have line width I want the width of my line to be five so I have put in here five similarly I've have done for the next plot as well then I've added title which you know how to do that similarly y label and X label now after that I'm using this Legend function in order to add a legend to My Graph over here you can notice that we have it present in a graph where I'm pointing with my highlighter right now so we have line one and line two after that what I've done I have added grid lines to my graph which is of the color k which is nothing but black so you can see it in my graph as well we have grid lines available and finally PLT Dosh any doubts questions still here guys we are going to execute this practically in my py charm so before that if you have any questions or doubts you can ask me all right so we have no questions so I'll open my pie charm again and I'll show you how you can do that practically so this is my py charm again so this is my py Cham again guys let me first remove all of this and I need to import the style function so for that I'll type from matplot lip import style that's it style. use ggplot now Define the variables first will be X add certain values to it l in 5810 58 10 then y I'm going to add list of numbers 12 16 6 X now one more variable X2 again it'll have list of numbers which will be 6911 then I'm going to use Y2 variable and I'll add some numbers to it 65 and 7 all right so now I'm going to use PLT do plot function and over here first I write X comma y then now given a color to it I'm going to give it as green next label line one now line width which is equal to five now again for X2 and Y2 I'm going to type in PLT do plot X2 comma Y2 comma the color then label so I'm going to type in line two then comes line width all right so now our next step is to add title to our plot so plot pl. title and the title that I'm going to give is info again then X and Y labels PLT do y Lael y AIS then PLT dox label xais PLT do show now go ahead and run this so over here I've not added any grid lines I can do that as well so for that let me first close it fine so I've defined title XL as well as y label now our last task is to actually add grid lines so for that I'll type PLT do grid and just write in here true comma give a color I want it black so I'll keep it that way finally show your plot so PLT Dosh that's all go ahead and run this so you can see that this is our graph so we have changed the default linewidth we have added grid lines we have added labels titles plus we can add Legend as well so let me show you how you can add a Legend So for that I'll go back to my code once more just write in here PLT do Legend go ahead and run this again and you'll see that Legend has been added so here we have line one and line two as our Legend and we have changed the default line width title y-axis x-axis labels plus we have grid lines so this is how you can customize and add style to your graph so I hope you all are clear all right so everyone says they are clear so what I'll do I'll open my slides again and we are going to look at how to plot various types of graphs for example a bar graph or a histogram all those things fine so first we'll look at how to plot a bar graph so these are all the leader graphs that we have seen till now now we'll see how to plot a bar graph so before I tell you how to plot a bar graph using ma plot let us understand why we actually use a bar graph so bar graphs are basically used to compare things between different groups and when we are trying to measure changes over time bar graphs are very well suited when changes are larger so this is why we use bar graph now let us understand how we can do that using matte plot lip now since we know why we use bar graph let me explain to you the code and how you can do that using M plot lip so first import pip plot like we do every time after that instead of PLT do plot I'll use PLT doar and I have filled in data here you can fill in variables as well that contains data then I have defined a label example one after that I have we more plot in which I have filled in data plus a label and I've given a color as well I don't want the default color I want some change so I've written it as green after that I've plotted the legend after that comes Legend and then X label and Y label that you have seen in the previous graphs as well then I've added a title and then finally show it don't worry guys I'll execute this practically in my pie charm now so this is my pie charm guys over here what I have done first of all I have imported the P plot function then instead of PLT do plot I'm using PLT dobar and inside that I have data filled in instead of that I can even have variables that contains data then comes label in which I am using example one then comes label for this instance it is example one then again for one more plot I have PLT do bar inside that I have data filled in then label and then in order to differentiate between both of them I'm using a color green for this particular bar graph then comes and then after that and then after that I've defined X label as well as y label after that I have title and then finally show it now go ahead and run this and see if it works or not and yes it does so we have Legend here we have ex X lab we have y Lael as well as X Lael and we have a title for our graph so any questions any doubts guys all right so we have a question from Dave he's asking what is the difference between histogram and Par plot all right Dave I'll tell you in histograms we have quantitative variables all right and when I talk about bar plot they have categorical variables so let me explain you this with an example so if suppose if I want to plot the GDP growth of every city in a particular country so at that time I'll use a barplot because it has a category this particular City like New Jersey New York all those things now when I talk about I'll use histogram when I'm talking about quantitative variable that means if I'm talking about age group in that same example if I want to calculate how much each age group is actually contributing towards GDP growth so at that time I'll be using histogram so I hope this answers your question all right he wants me to repeat it fine I'll do that so when I talk about histogram it actually has quantitative variables when I talk about bar plot it has categorical variables Now with an example if I explain you you can take the example of GDB growth so if I want to calculate how much GDB growth is there for every City in a country so at that time we use barplot but if I want to calculate how much each age group is contributing towards the GDP growth of a country then at that time I'll use a histogram so over there we had a category in bar plot like cities but here we have a quantitative variable that is age group so I hope this answers your question all right he says yes fine all right so let us move forward and focus on the code that you have in front of your screen so let me explain you this code so over here we have population ages so we have defined a list in which we have multiple numbers after that we have defined one more list or a variable bins in which we have multiple numbers again now instead of using PLT do bar for barplot for histogram we use hist PLT doist then comes population ages instead of data I'm filling in here variables that contains data then bins then his type I want it to be a bar type now when I talk about his type I want it to be bar then the width should be 08 that's all rest all you can understand it is X label y Lael title Legend and finally show the plot now I'll go ahead and execute this practically in my py charm so this is my py charm guys and just to save time what I've done I've actually copied it already so over here you can see we have imported the M plot Li module then we have a variable population ages and bins now instead of using pl. bar I'm using pl. his for histograms then comes the two variables and then his type is equals to bar and then I've defined width similarly I have defined X Lael y Lael and title like the previous examples then comes Legend and then finally show the plot so let us go ahead and execute this and see if it works or not yep it does so we'll move forward and understand scatter plot as well now before we understand how to plot a scatter graph we need to understand why we actually use Scatter Plots usually we use Scatter Plots in order to compare two variables or three if you're plotting in three dimensions looking for a correlation or groups so basically you try to find out how much uh two or three variables related to each other so over here as you can see there is one point here and there's another Point here so these two are pretty much dissimilar to each other right now when I talk about these two points they're pretty close to each other so you can say that these two are pretty much similar and basically what we are doing here we're trying to find the relationship between the two variables and that and that is actually called your correlation now let us understand the code now let me explain to you the code so first of all all we have imported the P plot function from the M plot Li module then we have two variables X and Y which contains a certain set of values now instead of calling PLT dotplot or pl. bar or PLT doist I'm using scatter because I'm doing it for a scatter plot right now inside the parenthesis I have X and Y variables these variables contain data and I can even write the data instead of just writing the variables as well now I've defined a label and then color then rest of the things you know we have X label y Lael the title then Legend and then show that's all now let's go ahead and execute this practically in my py charm now this is my py charm and over here I've already paste the code so I'll just go and run this and we'll see what happens so this is how our scatter plot looks like so here we have our Legend then we have the title then we have our y AIS then x-axis these two are the labels for that so let me close it and see what is the other plot that we are going to focus on now once scatter plot is done we'll have look at the area plot or you can even call it as a stack plot so basically these area graphs are very similar to the line graphs okay they can be used to track changes over time for one or more groups area graphs are good to use when you are tracking the changes in two or more related groups that make up one whole category you can take an example of say public and private groups okay so before I explain you the code let me tell you one thing guys the problem here is with polygons we cannot actually have labels for our data in order to to solve that problem all we did here was plot some empty lines giving them the same color and the correct labels in accordance with our stack plot we also gave them a line width of five as you can notice here to make the lines a bit thicker in the legend now we can easily see that we are spending our day sleeping eating working and playing so this is how the code works now let me execute that practically in my pie charm so I've copied the code already just to save time again now this is our code over here I've already explained you why are we defining these empty lines just to add labels now let us go ahead and execute this and see what happens so this is our graph guys and again we have Legends title to our graph and Y Lael as well as X Lael so we'll move forward and look at various other plots this is called a pi plot so let me tell you about pie charts a bit so pie charts are pretty much similar to stack plots only they are for a certain point in time typically a pie chart is used to show paths to the and often a percentage share you can consider the example of percentage of market share and things like that right now let me tell you guys matplot lib handles the sizes of the slices and everything so all we need to do is just feed it the numbers that's what we have done here so let me explain you the code here so over here we have so over here we use pl. piee in to plot a pie chart we have slices we have specified slices now slices which are nothing but the relevant sizes for each each part then we specify the labels and then the colors list color list for the corresponding slices next we can optionally specify the start angle for the graph this lets you start the line where you want in our case we chose a 90° angle for the pie chart which means the first division will be a vertical line next we can optionally add a shadow as well and after that we can even use explode to pull out a slice a bit so we have exploded that say 0 comma 0.1 comma 0 comma 0 so because of that you can see that eating has been pulled out a bit now basically we have four total slices so with explode if we didn't want to pull out any slice at all we would have just written here 0 0 0 0 now if we want to pull out the first slice a bit we would do 0.1 comma 0 comma 0 comma 0 and if we want to pull out the second slice a bit what we can do is 0 comma 0.1 comma 0 comma 0 like in our case now finally we do an autopack now this autoa overlay the percentage on the graph itself so you can see that we have 8.3 29.2% 54.2% all those things written on the graph itself and then finally add a title and then show it now let me execute this practically guys now just to save time I've already written the code so I'm just going to go ahead and execute this and we'll see if it comes or not yep here is our pie chart so we have seen multiple types of plots we have seen P plot bar plot histograms area plot now what we need to understand is how to handle multiple plots so at that time what will you do let me open my slides again and we'll move forward with that so this slide actually tells you how to deal with multiple plots now you can notice in the figure as well we have two plots available now let me help you out with the code that is there in front of your screen so in the beginning we are importing a couple of modules one is matplot lip. pyplot which you are already familiar with after that there is a numpy module as well so we have covered numpy modules in the previous sessions if you have any doubts you can go through it now after that you might find this part confusing if you're not familiar with numpy now let me just tell you what it does it will create a numpy array that will have elements between 0 to five in the steps of 0.1 now similarly T2 will also be an npy array that will have elements ranging from 0 to 5 and in the steps of 02 now after that the code is pretty much similar to the previous examples that we have seen but there's one New Concept that is called subplot now let me tell you what this subplot does it helps us to plot multiple plots all right so when we write subplot 211 this means that we have two plots horizontally we have only one plot present and vertically we have two plots and in that vertical position this plot will be our first graph now you can notice that we have one more subplot that is 212 so so vertically we have two plots horizontally we have one and this is the second plot so what I'll do I'll open my pie charm and I'll play around with it a bit so that you'll be able to understand it better so now this is the code guys first I'll go ahead and execute this and we'll see the result so we have a graph something which is like this right we have two plots which are aligned vertically now what I'm going to do is I'm going to just minimize this and I'm going to change the subplot value so that you'll be able to understand better how we are dealing with multiple plots now over here if I make this as two and this one as well as two so let us see what we get so we have got the same graph but it is aligned horizontally if you can notice this is our another graph and this is our first graph so you can notice the difference between both of these graphs right so this is why we use subplot so we have certain values in the subplot right 2 two and one now what does two means that we have two graphs available with us after that whether I'm aligning it horizontally or vertically so if I'm doing that horizontally horizontally I have two graphs then among those two graphs this is my first graph this this is what it means now similarly when we have 222 here this means that we have two graphs horizontally we have two graphs available and this is the second graph that is present so similarly if I make a change here and I make this as 211 and this as 212 this means that horizontally we have only one graph and these both graphs are aligned vertically so we have this is the first graph and this is our second graph this is how it works so this is what basically subplot is let's try a quiz question now how do you correctly plot a line graph in Python using mat plot lip and the options are PLT do plot of X comma y option b plot X comma y option C plot. PLT of X comma y or option D PLT of X comma y please comment the right answer in the comment section below after mastering matplot LIF we will discuss python function this topic will teach you how to create and use functions to make your code modular and reusable why we actually require functions so guys here I have for you a really simple use case consider this program right so let's say you actually write a program in which you input a Celsius number let's say a temperature of course and this must be converted into fahrenheat multiple number of times what would you do we first obviously start with the logic right so Fahrenheit is equal to 9x 5 into the particular Celsius number + 32 so this is the logic to calculate for fahrenheat well here's the program to calculate for the fahrenheat right so we collect the input from the user we enter the Celsius value again the value in Fahrenheit has been converted and it has been printed well it is really good right so this has been done once but what if you actually want to do it multiple number of times well let's say you have 1 Celsius value then definitely it is really easy right so let's say you have 3,000 5,000 let's say you have one lakh values that needs conversion in real time as well so when this happens you wouldn't want to repeat the same lines of code right well this is the number one cause of inefficiency and ambiguity guys well I'm sure you already would have guessed it right so python functions definitely solves this let us check out how it can be done well just before that let me give you another instance we have something called as dry well dry is don't repeat yourself in the sense when you're actually writing your own functions or when you're writing any methods make sure that the reusability of it is really high functions not only reduce the code in your main program but they also tend to make your code run faster and better so what does this do this actually increases the readability of your code and then makes it very easy for debugging and documentation as well consider this easy example right so every time you turn on or turn off your television there are certain functions built in right so as soon as you flip the channels or say adjust the volume there isn't anyone in the back end writing a code at every point of time to actually adjust the volume or flip the channels for you there is a particular code which repeats itself and doesn't create any new instances when you actually adjust the volume or flip the channels correct so this is again very good efficiency so as soon as you change the channel there is a function which runs which says that the user has changed the channel so let me do these certain set of quotes again similarly for the volume as well so if you have increased the volume or decreased the volume the function gets an input of what you're actually doing and then this function actually works on your input and then decides an action in this case it's volume pretty simple right well now that we know why we need functions right so let us check out what functions actually are so what are functions guys I'm pretty sure every one of us has an idea at this point of time so head to the comment section below and let me know what you think of it I'd love to interact with you guys there so coming back what are functions guys functions are actually a way to break problems or processes down into smaller and independent blocks of code straightforward right so it's basically a block of organized reusable code that is used to perform some similar task in our last case in television it was either adust the volume or change the channel well coming back to python it can be called by its name when it's task need execution you can also pass the values to it and have return results to you do not worry I'll be walking you through a range of functions so you'll have a better Clarity at this point of time well at this time all I want you guys to do is to know about the def keyword guys def stands for Define and this keyword is actually used before the name of the function and its name is followed by the parenthesis before a colon well this defines an entire function check out this particular example code I have for you so we have def function and disord name and this function does nothing and pass definitely right so we haven't passed anything there for the function to do anything well def is the keyword here function underscore name can be anything it can be my name an it can be edua it can be anything that you like right it's as simple as that so let me quickly introduce you to another concept called as doc string so guys what is dock string it's actually called as a documentation string so it's basically the first string after the function header is called right so this particular thing is called as the doc string again as I mentioned it is short for documentation string check this particular example out right so we have print greed doore doore uncore what does this do well this function greets to the person passed into the name parameter so if there's a name parameter in the documentation the function actually greets the person which is passed by the name simple now check out this important flow I have on the left side for you guys again we're going to come back to this but right now you need to know this we actually first Define a function followed by the function name we have certain set of code right in the function or away from the function or anything well good we actually wrote the code until now well later when we actually need to use it we actually call the function by its name as you can see Define function name will actually Define that particular function and what that function actually should do to call the function and by calling the function I mean to actually make use of the function we just use the name of the function so here instead of Def function name in the second line of code we have function name so this is where we'll actually be using the code so this sort of flow is actually important and I want you guys to note this at this point so now that we're good with the basics next up I want you guys to check out the different types of functions available in Python so guys there are two main types of functions in Python first one is built-in functions and the second is user defined functions well as you might have already guessed that but built-in functions are already available with python natively and user defined functions are something which are defined by the users right so there are n number of buil-in functions for almost all the users guys so for the sake of Simplicity in this tutorial I have considered the buil-in functions which are actually part of the Native python package well with python as you already know there are n number of libraries so each library has multiple functions on its own so as soon as you go into the depth of one single Library you'll get access to all of their functions as well and in user defined functions again as the name suggests you can Define whatever you want so basically let me give you a quick simple example right so consider the example of a calculator so let's say 3 + 5 is equal to 8 right so let's say a + b equal to C you've written the function you're going to pass the values a plus b and then you have a function which automatically gives you the value of c and you don't have to write a plus b equal to C all the time so we are basically trying to reduce the amount of effort put in by the user and and increase the readability as well so there is absolutely nothing to lose when you make use of functions and its advantages from the start to the end and it's all advantages from start to the end so let me quickly walk you through some of the major built-in functions which are available in Python so guys the first function I have for you is the absolute function I am sure many of you can guess what the absolute function already is but let me walk you through this function right so first I have the definition for you so basically the absolute fun function Returns the absolute value of a specified number well that's confusing what do we mean by absolute value consider this particular syntax and example well the syntax is ABS of n here ABS is the keyword and N is the parameter pass so n can be anything right so it can be zero it can be 100 it can be anything it has to be an integer here guys that is really important to note so here all we're trying to do is we're trying to return the absolute value of a number so consider the example right so we have a complex number here x is equal to Absolute of 3 + 5 J well what does this do so this basically calculates a number for us which is actually a complex number in this particular case and then provides the absolute value for it so let's say instead of a complex number we had absolute of Min - 7 what do you think was going to be the answer right so it's going to be seven obviously so in this case it was minus 5.83 and since it's absolute minus has been removed and it's here so what is the answer to x equal to Absolute of -1.5 can you guys take a guess well definitely it is 10.5 right so there is no negative in terms of absolute simple and straightforward here the parameter which is n it is actually a number so make sure you don't put any string input such that you can avoid all the errors so the first function is done so let's quickly move on to the second one so guys the second function I have for you is the all function well the definition actually says this the all function returns true if all of the items in an iterable are true otherwise it returns FAL false but what are the iterable items that we talking about right so it can be lists it can be tles and it can be dictionaries as well right but you need to note one thing about the all function so if the iterable object is actually empty then the all function will still return true so let's quickly take a look at the syntax and the example and the output as well so syntax all of ible you already know that the all here is actually a keyword check out the example we have a list here right so my list is equal to true true true and X is equal to all of my list well it's basically telling us that all of the elements present inside our list is actually true and it matches so as soon as you check out the output it says true why because everything is true this is the same case for lists tles and dictionaries as I mentioned so make sure you know that as well pretty simple right so we already covered two functions in such a short amount of time let us quickly jump into the third one so this third function is a very interesting function guys so it is aski I am pretty sure many of you actually know what aski is right so ask actually stands for American Standard code for information interchange and all it does is it is a character encoding standard guys so it is basically used by computers to actually understand so we understand a to zed and 1 to th000 or one to million right so how can computers make sense of this information in their lowlevel language is exactly through asky so what does the aski function do in Python well the asky function actually returns a readable version of any of the objects here objects are strings tles and list or anything right and the asky function will actually replace any non asky characters with Escape characters so if it's an asky character well and good if there is no asky character it'll actually Escape that particular character guys so here's the syntax check it out we have asky of object again asky being the keyword and object being the parameter so what is the object parameter here right so it's a string it can be a list it can be a tle it can be a dictionary and anything you want in your particular instance check out the simple particular example here so we have an x equal to aski and my name is tal the a here is spelled very differently and it does not have an asky value map to it right so if it was just stale then you would actually get the aski output well since here it is not a valid aski character python actually puts an escape sequence there and it actually escapes that particular thing and prints out the rest of the thing simple right well I'm going to assure that all of the functions are actually as easy as this and then it would make your life easier to know what each of these functions and at the end of the day it'll make your life really easy knowing what all of these functions do so on that note let me quickly move to the next function so the next function I have for you guys is bull well bull actually stands for Boolean can you quickly take a guess again cool I'm sure you would have guessed it by now the bull function actually Returns the Boolean value of a specified object well it will actually return true unless it meets empty parentheses or empty brackets or if the object is false if the object is zero and if the object is none as well so all these cases are when it can be false but any other time it will actually return true so let me quickly walk you through the syntax bull of object bull being the keyword object being the parameter so what is the object in this particular case it can actually be string it can actually be list it can actually be numbered or anything right so check out this particular example X is equal to BU of one so as soon as that happens since it doesn't match with any of our false criteria we got it as true simple right and now that we are actually done with the bull function let us quickly check out our next function next function is enumerate and this is definitely interesting guys so the short form of enumerate actually stands for inum but in Python we actually use enumerate so in case you're coming into learning python from an other different language say C C++ or Java or something you would realize that enumerate here is the same as inum there again let me quickly show you the definition of it so the enumerate function actually takes a collection again a tle is a collection right and it takes this as input and returns it as an enumerate object the enumerate function adds a counter as the key of the enumerate object let me give you some better Clarity on this check out the syntax right so enumerate and it has two parameters instead of one so one is iterable and the other one is start what is iterable so we already checked out what iterable objects are and then we have something called a start well start is actually a number we are trying to define the start number of the enumerate object well if you don't put anything it'll be zero well check out this particular example right in front of you right so we have X is equal to apple banana cherry and Y is equal to enumerator of X so again the default value is zero so python already Counts from zero instead of one right so obviously Apple becomes zero banana becomes one and Cherry becomes two and you can actually play with all of these Kei mapping values and then operate on them later as well but at this point of time all you need to know is this python starts from zero and the first object there first iterable object there actually starts from zero so Apple to zero and so on from there guys simple right and now that we are actually done with the enumerate function let us quickly check out the format function so what does the format function actually do so guys the format function actually formats a specified value into another specified value well that was a bit complex right so let me quickly simplify that for you guys so check out the syntax we have format and we have two parameters value and format well a value can be a value of any format guys and then we have something called as format guys I'm talking about the parameter here and not the keyword so basically we have multiple parameters guys so we have lesser than so lesser than basically left aligns the result and then we have right align and this actually aligns the space then we have is equal to so this basically places the sign to the leftmost position and we have minus so this is actually used for a negative value as you already know it then we have b b actually converts it to Binary C converts it to UNI code D to decimal F to a fix Point number G to to General point and so on guys and if you want more it is basically o for octal lower case X for hex uppercase X for uppercase hex format n for number format percent for percentage format well in this particular case check out this example we have X is equal to format of 0.5 and percentage right so 0.5 in percentage is what so it is basically 50% right so it is basically half so 50% is your answer another function done so what is the next function I have for you guys the next function is actually get attributes so basically it is shortly called as get ATR again a keyword so what does this function do guys the get ATR function actually Returns the value of the specified attribute from a specified object again looking at the syntax we have get ATR we have the object attribute and the default parameter the object is compulsorily required because we need to know what we're working on right so this is the compulsion and then next we have the name of the attribute right so basically it is a name of the attribute from which you want to get the value from and next we have default guys default is optional here so what does it do basically it is the value to return if the attribute does not exist so in case there isn't any particular attribute to return to it returns to this default value check out this really simple example I have for you guys so we have a class called person name equal to John age equal to 36 country equal to Norway X is equal to get attribute of person and age so at this point point of time what we're trying to do is move into the class person find me the age of this particular instance so in this particular case John's age is 36 and that is exactly what we see in the output pretty easy right and now that we're done with the get attribute function let's see what's next so this is an interesting function guys so I have the identity function for you guys so guys this is an interesting one the identity function also for short it's called as the ID function so what is the definition of this function guys the ID function actually returns a unique identifier for any specified object so all the object in Python has its own unique identification right so the ID is actually the object's memory address and it will be different for each time you run the program check out the syntax and the example guys so ID of object as you can already tell ID is the keyword object is the parameter here the object can be anything guys it can be a literal object it can be a string it can be a number it can be a list it can be a class or anything thing as such check out the example X is equal to apple banana Cherry Y is equal to ID of X well this particular object created has the identification as this so when you actually perform operations on this particular object on X and then python basically tracks it in the background using this particular identification guys so every object in Python is actually mapped to a particular unique identifier it may not be the same every time but what is important to know that it actually has has a unique identifier so if I probably ran this program twice and then showed you the same output it would actually not be the same because another identification number would have been provided so identification function is as simple as that guys so let us quickly move on to the next function so the next function I have for you guys is the length function and it is shortly called as Len so guys the length function basically Returns the number of items in an object so consider this right so when an object is a string the length function actually Returns the number of characters in that particular string check out the syntax so we have Len of object right again object is definitely a mandate here because we need to know what we're trying to find the length of right so either it must be a sentence it must be a string or it must be a generic object or it can be a sequence or even a collection as well so check out the easy example I have keed for you right so my list equal to hello so we have one word here right so it consists of five letters so as soon as you print x equal to Len of my list it realizes that this is a string and it prints the number of characters in hello there are five characters and as you can see the output is five well length function done guys the next function I have for you guys is the map function can you quickly take a guess on what the map function actually does so guys the map function basically executes a specified function for each item in an iterable sequence so this basically tells us that the item is sent to the function as a parameter right so we need to know what we actually doing here so check out the syntax map is the keyword and we have two parameters which is function and iterable guys so function is definitely required because we need the function to execute for each particular item right and then we have iterable well in this particular function again iterable is also a compulsory requirement because we need to know right we need a sequence or we need a collection or an iterator object or something to work on so you can basically send as many iterables as you can and just make sure that the function has only one parameter for each iterable quickly check out the example and the code and I'm pretty sure you guys will figure it out on your own so basically we have defined my function of n again defining the function name name of the function is my function my funk and then the parameter is n what we are actually going to do is we are actually going to return the length of our input parameter check out the next line x equal to map of my funk and then we passing it three values apple banana and Cherry right so what do you think is the length of this so each individual object can be iterable right so Apple has five characters and five banana and Cherry has six each so six characters each again pretty simple and widely used guys so this function actually helps you a lot when you're actually trying to map something to a key or when you're practically trying to make use of this so now that that's done let me quickly walk you through the next function so guys the next function I have for you is the Min function Min or minimum right so this function basically Returns the value with the lowest value or it returns as an item with the lowest value in a particular iterable so if the values are strings then alphabetic comparison is actually done let us quickly check out the particular syntax here so we have Min of N1 N2 N3 so it can be any number of numbers and then we can have another syntax actually right so what do we do if it's an iterable so instead of N1 N2 and N3 or so on we're going to have Min of ible guys as simple as that but check out the example here for Simplicity sake we have x equal to Min of 5 and 10 so it's as simply as saying what is the minimum of 5 and 10 so which value is minimum here five right so if I had to give you another example what is the minimum of 1,000 and 10,000 so whatever is the minimum number is output right so in that case it was actually th000 so it is as simple as that right so I don't think I need to explain more about this and you guys got a pretty good idea about it already so moving on next I have for you guys is the P function P stands for power so it's basically exponentiation here guys so the function actually Returns the value of x to the power of Y well in this particular case X raised to the power of Y guys so there are two parameters present right so what is the base and what is the power so if there is a third parameter then it Returns the X to the power of Y and the modulus of Zed quickly check out the syntax and the example guys so we have three parameters in this case right so it is pretty simple to pick up two parameters so let's say what is 2^ 3 the answer is eight correct so what is 4 power 3 again it is 64 if you actually required the modulus of this answer then that would be become our Z parameter in this particular case since we haven't done it 4 part 3 remains to be 64 and that is the exact output that we get simple right it is as simple and as easy as that guys so next up I have for you is the print function this is probably the first thing that you would learn as soon as you start Python and this is definitely not the last thing and this is definitely not as easy as it sounds so it basically prints the specified message to the screen or any other standard output device well most of the time it is this screen but you can actually do it to other devices as well so print so print we have objects then we have separators and we have files and we have flush and we have so much around here right so let me quickly walk you through all of these in a simple way so objects basically refers to any object right you can have any number of objects you want all of these will be converted to a string before it is printed and then we have separator guys guys separator is actually an optional parameter and you specify how to separate the objects if there is more than one object present the default separator is actually double codes and then we have end well again another optional parameter so we use this to basically specify what to print at the end the default is actually sln because again we're going to move to the next line as soon as something is printed and then we have file all of these are optional guys so basically file and flush everything is optional here as well so file is basically an object with the right method that's it but what if there isn't anything well the default of the file well the default parameter of the file object is actually assist. St out so it is the system standard out guys and lastly we have flush well again flush is another optional parameter as I told you and this is basically a Boolean specifying if the output is true or false well here is a computer science term for you guys if the output is true we call it to be flushed or if the output is false we call it to be buffered what is the default output it is buffered so what is buffered buffered is false so the default output is false guys again probably the most widely used example will ever have for you guys is printing hello world so print our separator is the double quotes and we're printing hello world again I hope no more explanation is needed for this particular function guys so moving on we have the set attribute function guys so this function basically sets the value of the specified attribute of a specified object again object here is required because we need to know what we're working on the attribute is required because we need to know what attribute we have to set and the value right so we need to know what value to what attribute we set so if you already remember we actually did the get ATR right so we actually outputed a function and now we're going to basically set it so check out the simple code I have for you guys we have class person and then name equal to John age equal to 36 country equal to Norway same as the previous example right so here we using another syntax at at of person age and 40 all we're trying to do is instead of John having his age to be 36 change the age of John to 40 so go into the class person look for age so whatever is there change it to 40 as simple as is that again this is a fairly straightforward function guys and next up I have for you is the sorted function what does this do well the sorted function actually returns a sorted list of the specified iterable objects you can actually specify the ascending or the descending order as for your requirement the strings are actually sorted alphabetically and the numbers are sorted numerically as simple as that but you need to know that you cannot actually sort a list that contains both string values and numeric values so you either can do it for numeric values alone or string values alone got it right so check out the syntax so we have something called a sorted and we have three parameters right so iterable key and the reverse iterable is definitely required because we need to know what sequence we need to sort either if it's a list dictionary or a tle key is optional guys key and reverse are actually optional here the key is basically a function which is used to decide the order well what if you don't give any order default is actually none and then we have reverse so what is a reverse guys again it is a optional function as I told you and it definitely is a Boolean function so false will actually sort it to be ascending and true will actually sort it to be descending default is false so default is actually sorting via ascending method so check out this particular case I have for you right so we have a set of values for a we have b g a d f c h e whatever right so X as soon as we print sorted of a the default value is false so in this particular case what happens is that so it actually orders it for us in the ascending order so the values actually went from being gibberish to be neatly sorted as shown here again another easy function done so this brings me to the last built-in function for the session so I have the type function for you guys so the type function basically Returns the type of a specified object so again check out the syntax we have type which is the keyword we have object basis and dictionary right so the first one is required we need the object here because we need to know what we're trying to find out the basis and the dictionary are actually optional so basis actually specifies the base class and the dictionary actually specifies the name space with the definition of that particular class well it is not that you need to worry about this right now but then definitely this particular and definitely this particular parameter which is Dick is actually useful later but for now since I'm introducing functions to you let's stick to the basics so check out this particular example I have a equal to apple banana and Cherry b equal to hello world and c equal to 33 so as soon as you try to find out the type of a b and c you can realize right so the first one as soon as you look at it it's a topple second one as soon as you look at it it's hello world and third one is definitely an integer right so ABC respectively so again as easy as that guys so those were a lot of functions and I actually recommend that you guys pause the video at every point of time and make a note of all of the important stuff that I've said here guys so this will actually take you a long way in learning python well now that we're actually done with the built-in functions again let me quickly give you a recap and then start with user defined functions guys so what are user defined functions again as I said we'll be taking the code first approach here so here I have for you guys two simple syntaxes so the first one is how we can actually create a function and the second one is on how we can actually call the function so we have actually looked at this when I previously told you but let me quickly tell it again so again Define my function define is the keyword my function is the name of the function so what what do I want this function to do I want it to print hello from a function so this is actually the body of the function and as soon as the function has been called it's going to print hello from a function well instead of print I could actually make it to calculate something for me or print my name or print edureka's name or anything as such as well right so the body of the function is completely left to your freedom but make sure you check the number of parameters you require and all that you need right so now quickly look at how we can actually call a function so we have defined my function and then hello for function as well to call this particular function all you need to do is call the last line guys so basically we need to type out my underscore function and you good so how more simpler can you expect python to be right as simple and straightforward as that so then again parameters guys so parameters are the information passed to functions that you already know so let me quickly step up the complexity of our examples to one little Notch higher right so again check out so we have defined my function and F name here F name is actually the parameter of us so we're printing F name plus ref so what we're trying to do we're trying to pass so this is our function body so next what we actually trying to do is we're actually trying to print it so we have mycore function we' have provided three names there we have ml we have Tobias and we have Linus right so as soon as you go ahead and check out the output on the right side so that is actually concatenated to ref nness right again simple so you can have any number of parameters and then work on all of these parameters and get whatever return output you want guys and get whatever meaningful return output that you want so what is the default parameter value that we stumble upon all the time again check out the example here so we have defined my function country equal to Norway so I'm specific finding in my parameters that the country is equal to Norway so no matter what you do right so in case you haven't provided any value the default value it should actually consider is Norway so we're printing I am from and then concatenating a value of the country we've called the function four times in which the first time we have said Sweden so it's printing I am from Sweden the second time it's India so I am from India third time we have just called the function without passing any parameter to it right so this is the exact case where it moves to the default value since nothing is provided it is actually printing I am from Norway and then fourth one my function of Brazil again it is as simple as that you've already provided the parameter so print it as it is so default parameter value you got all of this right and then the important concept you need to know is the return value guys check out the example we have my function and X is our parameter we're returning 5 into X so basically as soon as we pass a number five is going to be multiplied to that number and we going to get the output my function of three 5 3 is are 15 15 so next we have five 5 5 are 25 25 is correct 9 5 are 45 again we have 45 as the output so we're good with that right so let me quickly recap on how the function actually works so we have one set of code and we actually keep using it in recursion so recursion is basically a function calling itself so check out this particular example I have for you guys we have defined a function we call it tror recursion we have a parameter K so if K is equal to 0 then add the result to whatever is lesser than the next iteration of this function I know it sounds complex but how you can actually analyze a recursive function is to take a pen a paper so to write down the values of K at every point of time and then to actually Trace what is available in the memory guys so if that is the case and if the result in which K is greater than zero we print the result else we print it to be zero and we return the result and lastly we actually print the recursion example results and we call the function by passing s it a value of K right so K is 6 in our case so if K is equal to0 absolutely 6 Plus tror recursion of 5 again come into the function is 5 greater than Z correct again go back check if four is greater than zero yes keep doing it until the result is zero right so it's pretty much obvious at this point of time guys so every time you actually run this one value gets added to your program right so again check out the output and you will understand this better so we have one and then two values were added we got three three values were added we got six four values were added we got 10 five values 15 six values 21 so all we're trying to do is add one extra value and print it using recursion and that's about it guys so I hope this has been a good introduction to the python user defined functions as well so next quickly let us check out the Lambda function in Python guys so what is the Lambda function guys it is extremely simple a Lambda function is basically one small Anonymous function so it can take any number of arguments but it can have only one expression at the end of the day check out the syntax here so we have Lambda arguments and expressions well still nothing is working right check out the example we have xal to Lambda of a where the expression is a + 10 so as soon as we want to print something all we need to do is we need to print X of five as soon as we hit X of five a gets the value to be five so since a gets the value to be 5 5 + 10 becomes 15 and we're printing X of 5 which is now 15 pretty simple right so you basically can create tiny functions all on your own using the Lambda keyword here so do know that the syntax is really important because we have the arguments on the left side and the Expressions on the right side so guys here's another example I have for you so we have a Lambda function that multiplies one argument with another argument in our case it is a and b and we want to print the result so check it out x equal to Lambda of a comma B Because A and B are parameters here so what is the expression you want to perform between between A and B it is multiplication so A cross B and we're printing X of 5 comma 6 so a is 5 b is 6 what does 5 sixa it's 30 right again the output is 30 pretty simple check out this other example so basically we're trying to find the sum of three parameters a b and c and from the result so x equal to Lambda of a b and c three parameters a b and c hence three and then we have a plus b plus C so what is the sum of 5 6 and 2 it is 13 and that is exactly what you've got in the output so these are tiny set of functions that you can make use of any time without any dependencies guys so that is the important part I want you guys to notice at this point but when you can have all the regular functions why would you want to make use of the Lambda function right I'm pretty sure this was the first thought that came into your head as soon as I explained the concept well the power of Lambda is actually better shown when you use them as an anonymous function inside another function check this particular thing out we have defined a function which is called as my funk I have one parameter n and then we're actually performing an other function inside our function and this is basically telling us to return the Lambda of a cross n so whatever n value has been provided we're going to use the Lambda function as in a tiny function there to provide us the multiplication of a value with a particular n value which is the parameter simple so check out this example guys so we basically use that function definition to make a function that always doubles the number that you send in so we have defined my function of n Lambda of again a into n right so it's pretty much the same example and then we have a variable called my doubler which actually is sending the parameter two to our n value so what do you think is going to happen as soon as I print the value of my dou of 11 pretty much simple 11 gets multiplied by two because 11 is passed as a function into the my funk through my doubler so here A and N becomes 2 and 11 so what is the product of 2 and 11 it's 22 pretty much simple right so here's another last example so basically we can use the same function definition to make a function that actually triples the number that you send in so what I want you guys to not is that check out the function definition it Remains the Same so Define my function of n return Lambda of a into n perfectly same my doubler my function on how many times you want to double it so double is two so two my tripler equal to my funk of three so I want to triple it so multiply three times as soon as I print my douer of 11 11 into 222 is the first output that I get print my tripler 11 into 3 33 that is the second output that I get so what I'm trying to convey to you guys is that you wouldn't have to rewrite all of these functions at every point of time right so the definition of the function remain same how we call it and how we get our output is actually depending on us and that is what makes functions efficient and one of the biggest Concepts that you need to learn in Python guys now let's take up another question what is a recursive function in Python option A a function that calls itself option b a function with multiple written statements option C a function with multiple parameters or option D a function that only returns true or false please comment the answer in the comment section below now that you understand functions let's explore the python Lambda functions here you will learn about creating small Anonymous functions for quick and simple operations what exactly are Lambda functions python Lambda functions are functions that do not have any name they are also known as Anonymous or nameless functions the word Lambda is a keyword that specifies what followers is anonymous now that you're aware of what these Lambda functions are let's move on further to see why they are actually used the main purpose of anonymous functions comes into picture when you need some function just once they are created wherever they needed due to this reason python Lambda functions are known as throwaway functions they're also used within higher order functions which take a function as an input or return it as an output another very good advantage of using these Lambda functions is reducing the size of code and I'm going to be showing youall in this session how to do this so now let's move on towards our next topic which is to see how to write Anonymous functions Lambda functions are created using the Lambda operator and its syntax is as follows the first thing that you'll need to specify is the Lambda keyword and following that you'll have to specify the arguments or the inputs and finally after the colon symbol you'll have to specify the expression that needs to be solved Lambda Expressions can take any number of arguments so as you can see over here my first example is a Lambda expression without any arguments in the second example I've taken a Lambda expression which just has one argument A1 finally I'm demonstrating a Lambda expression which has inputs from A1 to a n just remember that all your arguments or inputs need to be separated by a comma so now let's move on towards our jupyter notebook and see how we can actually write these Lambda functions I'll just create a new notebook over here guys I'll just open a new notebook over here guys and I'll rename it as Lambda functions so guys now just let me write the syntax as a comment over here this is going to be good for a referral purpose so first is the Lambda keyword like I already told yall sorry guys for the spelling mistake Lambda and the arguments followed by the expression okay so the first thing I'll have to write down is the Lambda keyword following that I'll have to specify the arguments so let me just give one argument to this and after that I'll just say I want to multiply this a with itself so this is my Lambda function but before executing this I'll require some variable that can hold the value of this so I'll just specify that X is equal to this Lambda function and after this I'll say x of 3 and I'll hit run so as you can see over here when I used X of 3 it's returned the output to be 9 so guys if I had to solve the same expression using a normal function then I would have had to write a larger piece of code than this let me just demonstrate this to you guys over here so I'll just Define a function say new and I'll pass the parameter as a now I'll be using return to return the value of a St a to call this function I'll have to use the name of the function and specify some value to the argument that I've already passed so in place of a I'll pass the value as four or let me take it as three itself like the previous function and I'll hit run as you can see over here using Lambda functions I just required two lines of code whereas while using the normal function I had to make use of three lines of code along with this return statement over here okay so guys I hope you all have understood how to write these Lambda functions so guys as you all have just seen I've used Lambda expressions in the example along with some other variable X now I did this because these functions are nameless and require some name to be called but doesn't it seem confusing as to why assign a name to a nameless function and what is the need of it it's a legitimate question guys but the point is this is not the right way of using Anonymous functions Anonymous functions like I've already told yall are best used within higher order functions these functions either take a function as an input or return it as an output to demonstrate this let let me just move on towards our next topic of this session the first thing that we're going to study is anonymous functions within user defined functions so as you all can see on the screen I have a user defined function that takes the Lambda function as an input in this example over here the normal python function which in my case is new funk takes one argument X this argument is then added to some unknown argument which is supplied through the Lambda function let me just jump on to my notebook to explain this in detail let me just first create a heading over here guys just remember the number of prefixed hashes tells which heading it is so if it is H1 it will have one hash prefixed to it if it has two then it's H2 and so on so I'll just create a heading over here of H1 level and I'll give the name as user defined functions or Lambda within user defined functions Lambda Within user defined so I hope you guys know what are user defined functions okay so as you all know when you have to create a function in Python you'll have to use the DF keyword followed by the name of the function I'll just name the function as a and I'll pass one parameter to it say X after that I'll be using the return statement and within this I'll specify a Lambda function I'll pass y as the argument to this Lambda function and I'll use x + y as my expression now let me just give some value to the variable X and store it in another variable T So a of 4 and I'll I'll print the value of T of n or sorry eight and I'll hit run so as you all can see on the screen the Lambda function that is used within the function a is called Whenever I Call this higher order function and the first thing that I'm doing over here is passing a value to the variable X and then I'm printing the value of x + y so I hope everyone's understood this part okay now let me just copy this function and pass a few other values to this as well I'll just store a new value in the variable U and I'll pass the value for x as say 7 and I'll print of five and I hit run okay so I hope everyone's clear with this if you have any doubts please do let me know in the chat box and my team is here to help you now let's move on towards the next topic which is using Lambda functions within filter map and reduce functions the filter method is used to filter the given iterables which can either be lists sets Etc now this is done with the help of another function which is passed as an argument to test all the elements to be either true or false after applying the function to the set of iterables if the value is true then that value is returned in the output now let me just jump onto my jupyter notebook and use the Lambda function within the filter method I'll just give a new heading over here again just for your reference guys I'll create a heading of H2 level by prefixing it by two hash characters so I'll just use Lambda within filter and since is a method like I already told yall the filter function needs iterables now here I'll just create a list I'll say my list and I'll specify some elements to this the filter method is going to check for all the elements to either be true or false in accordance to the expression that is passed within the Lambda function like I already told yall the filter method is going to check if the expression that is specified with within the Lambda function is either true or false for all the elements that are present within my list and it returns all the elements that satisfies the expression so as a result I'll have a new list so I'll just name it as a new list and I'll use the filter function and within this I'll be using the Lambda function like I already told y all let me just specify the input as a and I'll give an expression over here say a I just want to check if any of these values when dividing div by three will equate to two and I'll pass my list and I'll pass my list as an argument to this and since the output is going to be a list I'll just use the list method over here and one more point I want you guys to note is the syntax of the filter function and since I forgot to specify this before beginning the demonstration let me just specify the syntax of this function over here I'll say syntax you'll have to use the filter keyword along with some function followed by the iterables okay so as you can see over here I have the filter keyword I have the function which is Lambda and then I've passed my list as the iterables to this function now let me just print the new list and I'll hit run uh oh sorry guys I've made a spelling mistake over here so it's f i l t e r so as you can see over here I've passed the elements 1 2 3 4 5 and 6 to this filter method and after checking if this expression is true for all the iterables it has returned six as the output now let me just cross check over here so if I divide 1 by 3 I will not get a result which is equal to 2 similarly if I divide 2 by 3 I'm not going to get the result as two again finally as we all know if I divide all these elements by three only for six I'll get the output as two so I hope everyone's clear with how to use the Lambda function within the filter function so now let's get back to our presentation and see how we can use the Lambda function within the map function guys the map function in Python is a function that applies a given function to all the iterables and returns a new list so I hope you're understanding what exactly it does it takes a fun function as the input and some iterables as well and then it applies this function to the set of iterables that are passed and it returns a new list so now let's get back to Jupiter and do the same I'll create a new heading of course and it's going to be Lambda within map and I hit run so before moving on towards the demonstration I'll just write the Syntax for the map function so it has to have the map keyword of course and the parameters that are passed to it is a function and the itbl now let me just make use of the same list which I was using previously and I'll copy that over here and then I'll just store the output in a new list p and I'll use the list function since I want the output to be a list within this I'll use the map function and to that map function I'll pass a Lambda function as the input I'll just pass one argument to this as a and the condition I'm going to specify is to check if any element present within my list divided by 3 is not equal to two and I'll pass my list as the set of iterables and then finally I'll be printing this now let me hit run so as you all can see over here it has returned a list with some Boolean values the expression that I wanted to check is a by3 not equal to 2 now let me just move on to my list and see what happens when I divide 1 by 3 of course I'm not going to get two so I have true as the output now when I divide 2 by 3 again I'm not going to have the output as two and therefore I have true as the Boolean value for this similarly all the elements present in my list are divided by three and it's going to check if the condition is true therefore only for six it's going to be false and I have the output as false okay so I hope you guys have understood how to use the Lambda function within the map function if you have any doubts please do let me know the chat box guys and my team will revert to you okay now let me just jump on towards our next topic which is using Lambda function within the reduce function so guys the reduce function is used to apply some other function that is passed as a parameter to it to a list of iterables and finally it returns a single value and to demonstrate this I'll just jump onto my Jupiter notebook again and I'll create a heading this is going to be Lambda within reduce and I'll hit run so first let me just write the syntax of this function it is the reduce keyword and it takes a function as a parameter the first parameter is a function and second is a sequence now to make use of the reduce function you'll have to import the fun tools library or from that Library you'll have to import the reduce function to do this I'll be using from fun tools import reduce you can also directly import the fun tools Library as import fun tools or you can also use from fun tools import Star these are just the alternate ways that you can also use over here okay so now I'll be using the reduce function and within this I'll specify a Lambda function and I'll pass two parameters say A and B and let me just print the sum of A and B and finally it has to have a SE quence as its input so I'll just specify a list over here I'll say the list of values to be 23 56 43 98 and 1 okay so now let me hit run and see what it returns so as you can see over here guys I have 221 as my output so what this reduce function is actually doing is it first adds 23 to 56 so guys the first thing that the reduced function does is ADD 20 3 and 56 and the output of this is going to be 79 now after adding these two values to this output it will add 43 so to 79 it's going to add 43 and it'll produce a new output after finding the output of 79 and 48 it's going to add the result to 98 and find it's going to add that result with one and Returns the final output which is 221 so I hope you guys have understood how this function is recursively adding each value to the next value that's present in the sequence guys if you have any doubts please do let me know in the chat box okay now let's move on to see how you can actually use these Lambda expressions or Lambda functions to solve some algebraic expressions for this I'll just go back to my Jupiter notebook and I'll create a heading over here uhoh sorry guys I'll just delete these two kernels and I'll create a heading I'll just say Lambda for algebra so guys first we'll be taking some linear equations so I'll just create a heading as linear equations so as we all know algebraic linear equations consists of variables of degree one which means they'll have the power as one so now let's just use the Lambda function to solve some linear equations I'll just say s is equal to Lambda and I'll pass the argument or the input as a and the expression I'll specify as a star a and I'll use S of 4 and I hit run so as you all can see over here 4 CR 4 is 16 now let me take a different linear equation so let me just write the linear equation over here as a comment so I just want say 3x + 4 y okay so if I want 3x + 4 y so I'll have to specify some name to this say d is equal to Lambda and X and Y as the inputs and since I want three star x + 4 star y okay I have 3 into x + 4 into y okay and then I'll pass the values as 4 comma 7 and I'll hit run as you all can see 40 has been returned as the output when I pass the value of x as 4 and the value of y as 7 now let me take some quadratic equation so I hope you all know what is a quadratic equation it's an algebraic equation with the degree 2 let me just give the heading as quadratic equation okay so now let me just try to solve the very famous a + b the whole square a + b the whole squar so I'll just say part two okay now let me write a Lambda function that's going to return the value of a + b the whole Square I'll just save it within a new variable X and I'll use the Lambda function and the arguments or the inputs are A and B the expression that I'm going to use is A+ B and like we all know we'll have to use double star when we use powers and then I'll print this x I'll pass the values of A and B as 3A 4 and I'll hit Run Okay so as you all can see I found the value of a + b the whole Square using the Lambda Expressions let's take up another question what will be the output of the following corrected python code option a 6 option b 5 option C 3 or option D 2 please comment the right answer in the comment section below you have got the hang of Lambda functions so let's move on to the arrays in Python you will learn how to manipulate and perform operations on arrays if you have any questions feel free to ask in the comments below our team is here to assist you what exactly is an array an array is basically a data structure guys with ordered series of elements any variable that is declared as an array can hold more than one value at the same time all values in an array have a particular address which is specified by its index number here as you can see on the screen I've declared a variable a as an array and I've stored values from 1 to 100 in my array which is a also make a note of the index values indexing always starts from zero and not from 1 therefore a of0 holds 1 a of 1 holds 2 a of 2 holds 3 and similarly a of 99 holds 100 when the length of my array is n the index value will be n minus one it is always one less than the length of the array so I hope you're clear with this topic now let's move on towards our next topic for this session which is the difference between Python lists and arrays python lists and arrays have the same way of storing data but there is a key difference that you all have to note arrays can store only single data type values whereas lists can store any data type values so for example if I have an array of integer values all values present in that array will be integers and nothing else on the other hand if I have a list then it can store integers together with float and cars and strings Etc now when you try to perform some operations like slicing or looping it will be similar for both but when you try to perform different operations like if you want to multiply your array values by two or you want to divide it by two you can do so easily when you have an array but if you try to do the same with the list it will throw an error because naturally you you cannot multiply cars and strings or divide them so I hope you're clear with the difference between these two so now let's move on towards the next topic how to create arrays in Python unlike other programming languages if you want to create arrays in Python you will have to import the array module now this module has all the functions that are necessary for creating and Performing various kinds of operations on arrays to import the array module you can use three ways first is to import the array module by its original name which is array the second method is to use an alas name this is the most widely and commonly used method as well in my demonstrations I'm going to be using this method the Third Way is using star from array import Star what this does is it's going to import all that is present in your array module now let's go to our Jupiter notebook and try to do this please do it along with me guys I'll open a new notebook and I will use the first me method to import the array module as you can see when I hit run no error has been returned which means this is executed now let's try to create arrays using this method as you can see over here I've created an array a using the first method so I have used array do array of integer values and I've specified some random integer values here the first array is the name of the module the second array is the array Constructor and then I've given a type code this type code specifies what type of elements my array will hold as you can see I've created an array so I hope you're clear with how to create arrays using the first method now let me open a new notebook and try the second method the reason to open a new notebook is because I've already imported array module in this notebook I'll rename this notebook because I'm going to be using this method in further demonstrations as well as you can see over here when I use import array as ARR ARR here is my alas name when I use this and hit run it does not throw any error now let me try to create arrays using this method I'm using int as my data type you can use any data type of your choice as you can see that an array has been created with some random integer values in place of the module name array I've used a RR now let's try the third method I'll open a new notebook again as you can see over here when I'm creating arrays using the third method I've just specified The Constructor name and then the type code and the value list so I hope you're clear with how to create arrays using all three methods okay so now let's get back to our presentation our next topic for this session is accessing array elements to access array elements you'll have to make use of the index values each index value holds a unique element like I've told you before indexing starts from zero and not from one so therefore a of0 holds 1 a of 1 holds 2 and so on this is the normal traversal order it starts from the left hand side and moves towards the right hand side but here I want you all to note this point as well that negative indexing also exists so negative indexing will start from the right hand side and move towards the left hand side therefore 100 will be at a of minus1 99 will be at a of minus 2 and similarly 1 will be at a ofus 100 so I hope you're clear with negative indexing now let's go to our Jupiter notebook and try to access some array elements as you can see over here I've created a heading to create a heading all you have to do is go to code select heading and prefix your text with the number of hashes based on the heading level you want so if I want H1 I will use one hash if I want H2 I will use two and so on here I've created a heading of H1 so I prefixed my text with one hash now let me try to access some array elements as you can see over here when I access a of two my output is three let's see where three is present in my array one is present at a of zero two at a of 1 and three at a of two so therefore when I access a of two three has been returned I are you guys clear with this just give me a quick confirmation before I move on towards the next topic Shashank says yes prti says please try to access something using negative index values okay prti let me show you that as well so here I've tried to access a of minus 2 a of minus 2 has returned five let's get back to our array a and see where five is present six is at a a of minus1 and 5 is at a of minus 2 therefore my output is five so prey are you clear with this okay preti says yes now let's move on towards our presentation and see what is the next topic our next topic of this session is basic array operations here I just want to tell you all something arrays are mutable which means they are changeable so in case you want to add or remove elements from it you can do so easily now coming back to our present presentation our first operation under this section will be finding the length of an array the second is adding or changing elements of an array and then we will try to remove or delete elements of an array and then guys we will try to perform array concatenation slicing and finally we will be looping through an array now let's move on towards the first operation to find the length of an array you will have to make use of the Len function now this function returns an integer value which is equal to the number of elements that are actually present in your array the Len function takes one parameter which is the name of your array as you can see in the example over here I've created some random array a and I've given some random values as you can see I have three values over here and when I use the Len function and I specify the name of my array the output is three which is equal to the number of elements that are present in my array now let's move towards a Jupiter notebook and see how this works as you can see over here when I use the Len function and I've given the array name which is a and integer value is returned which is six six is the number of elements that are actually present in my array which is a okay so I hope you're clear with this so our next operation is adding elements to an array in case you want to add elements to an array you can do so using the append extend or the insert function the append function is used when you want to add an element to the end of your array the extend function is used when you want to add more than one elements to the end of your array the insert function specifically adds a new element to a particular position in the original array let's let have a look at a small example of these three as you can see on the screen I've created some random array a and then I've used the append function and I've given the value that I want to add to my array as you can see in the output 3.4 which is the value I've specified to the pen function has been added to the end of my array which is a and then I've used the extend function please make a note over here that when you use the extend function you will have to specify the values between square brackets if you don't use the square brackets it will throw an error I've given three new values and all three values have been added to the end of my array and then I've tried to use the insert function over here I've specified the index number as two and the value to be inserted at that position as 3.4 as you can see in the output 3.4 has been inserted at C of 2 now let's go to our Jupiter notebook and we'll do the same I'll reprint my array which is a so that it's easy for us to refer to it since my array a holds integer values I will give some new integer value to it as you can see I've given eight as the value that I want to insert in my array and eight has been added to the end of my array now let me try to give some float value to this array and see what happens as you can see when I try to append some float value it gives me a type error therefore I can add only those values which is specific to the type of elements that are present in that array now let me try to use the extend function like I've told you all when you're using the extend function you will have to make use of the square brackets as you can see in the output all the values that I've specified within the extend function have been added to the end of my array now let me use the insert function I've used the insert function and the first parameter I've specified is the index value and the second is the element to be inserted at this index position so at index value a of two 6 will be inserted as you can see in the output six has been inserted at a of two so I hope you're clear with how to add elements to an array now let's move on towards the next operation our next operation is removing elements of an array in case you want to remove elements from an array you can make use of the pop or the remove function the pop function removes the element and returns it whereas the remove function will remove it but it will not return it the pop function can either take no parameters or one parameter the parameter it takes is the index value of the element to be removed if you do not specify any parameter it will remove the last element from the array the remove function takes one parameter which is the element to be removed itself now let's have a look at a small example of this as you can see on the screen I've created some random array a and then I've used the pop function without specifying any parameter as you can see in the output when I do not specify any parameter the last value present in my array has been popped and returned as well second time I've used the pop function and I've given some index value now this pop function will remove the element that is present at this index position as you can see it has removed 3.1 and returned it as well after that I've used the remove function like I've told you before the remove function takes one parameter which is the element to be removed and you can see in the output that the remove function has not returned any value after that I've printed my array and you can see all the values that are removed using these two functions are no more present in the array a now let's go to our jupyter notebook and do the the same let me reprint my array which is a first I will use the pop function without specifying any parameter to it as you can see over here when I do not give any parameter it removes the last element that is present in my array now let me give some index value to it I'll reprint my array a because I've removed an element from it now let me give some index value to the pop function as you can see when I use a. pop of two it removes the element which is present at a of 2 which is six and it returns it as well let me try to use some negative index value for the pop function a do pop of minus1 removes the last element that is presented my array which is five now I'll use the remove function let me reprint my array guys as you can see all the elements that have been removed using the pop function are no more present in my array a like I've told you before when using the remove function you will have to specify the element that is to be removed here let me remove eight because there are two occurrences of eight and let's see what the remove function does when I hit run remove function does not return anything now let me print my array a and see what is present as you can see the first occurrence of eight has been removed but the remove function did not return the value so I hope you're clear with the remove and the pop functions now let's get back to our presentation and perform the next operation our next operation is array concatenation concatenation means joining so in case you want to join different arrays you can make use of the plus symbol and as you can see on the screen I've created some random array A and B and then I've created some random array C which is empty also make a note that all three arrays have the same type code and then I've concatenated A and B into my empty array which is c as you can see in the output all the elements present in A and B have been concatenated into my array C now let's go to our Jupiter notebook and perform array concatenation I'm using int as my data type you can use any data type of your choice to create an empty array all you have to do is specify the type code and leave the value list empty here I've created an empty array D and I've concatenated B and C into my array which is D now let me hit run when I hit run all element elements present in B and C have been concatenated into my new array which is D so I hope you're clear with array concatenations let me just show you what happens if I try to concatenate arrays of different data types I'll just change one of my previously created arrays type code and I'll give it as float let's see what happens when I change the type code and I try to concatenate these two arrays you can see that I've encountered an error and it says type error which means it cannot concatenate two arrays of different data types so just be careful when you're concatenating arrays you cannot concatenate arrays which hold different data type elements okay now let's move on towards our presentation and see what is the next operation our next operation is slicing an array slicing actually means fetching some particular values from your array to do so you can make use of the colon symbol as you can see on the screen I've created some random array a and I've sliced it from 0 to three zero specifies from where fetching has to start and three specifies where it has to stop so it will start from zero it will go on till three but it will not include the value which is present at three as you can see in the output I have a of Zer a of one and a of two that is present in my output now let's go to our Jupiter notebook and we will try to slice our arrays I'll reprint my array D over here and then I will try to slice it as you can see I sliced my array from 0 to five so it will start from index number zero it will go to five but it will not include the value which is present at index number five you can also see the same in the output over here let me try to use some negative index value my output when I use 0 colon minus 2 contains all the values between 0 and min-2 but it will not include the value which is present at min-2 okay so I hope you're clear with this topic just give me a quick confirmation before I move on okay anel says yes Shashank has a question he asks what does colon colon minus one mean Shashank unlike what many of us think colon colon minus one does not reverse my array but it prints a reversed copy of my array so let's try to do this over here as you can see all the elements present in Array D have been reversed now let's print our array which is D the original array D is the same but colon colon minus one has reprinted a reversed copy of my array which is D this method but is actually not preferred because it exhausts the memory so I hope I've cleared your doubt Shashank just give me a quick confirmation okay Shashank says yes now let's get back to our presentation and perform the last operation of this session which is looping through an array you all might be familiar with these two Loops which is the for and the while Loops the for Loop iterates over the items of an array specified number of times whereas the while loop iterates until some condition is met or some condition is true when you're using the Y Loop you will have to keep three things in mind one is initializing your iterator second is to specify a condition third is to increment your iterator remember that if you do not increment your iterator your while loop will go on forever let's see a small example of this as you can see on the screen I've created some random array a and then I've used the for Loop to Loop through my array a I've used for X in a print X which means go to every element that is present in a and print it let's try to do the same on our Jupiter notebook let me reprint my array D now let me use the for Loop to Loop through this array for X in a print X which means go to every element in D and print it as you can see all elements present in D have been returned one after the other now let me try to slice this array and print specific elements as you can see over here I've sliced my array from index number 0 to minus 3 and I've printed only those specific values using the for Loop now let's go to our presentation and have a look at the while loop like I told you before when you're using the while loop you will have to do three things one is initializing your iterator second is to specify the condition and third is to increment your iterator let's try to perform looping on our Jupiter notebooks please do it along with me guys let me reprint my array D here I'm using the iterator as temp you can use any name of your choice as you can see over here I've initialized my iterator to zero and then I've specified a condition wherein I have told whenever the value of my temporary variable is less than D of 2 then print that value and then I have iterated the value of temp I can also use temp plus equal to 1 which is same as temp equal to Temp + one now let's try to use the Y Loop using the Len function here I will use my array a so let me reprint it over here as you can see over here when I use the Len function my temporary variable will go to all elements present in my array a and print them one after the other moving on to next question what will be the output of the following python code and options are option a edua option b edu option C Rea and option D none of the mentioned so please comment the right answer in the comment section below with arrays covered we will dive into inheritance in Python this section will show you how to implement inheritance to create a hierarchy of classes what is inheritance in Python if we take a look at a real life example inheritance is when a child inherits properties from their parents it can be the genes or it can be any other property characteristic so looking at it from the programming point of view inheritance is when a class inherits properties from another class the class which inherits the properties is known as a child class or the derived class and the other class is known as the parent class or base class now let's take a look at a few advantages of using inheritance in pyth so first of all it is mainly used for code reusability so that you don't have to write the same code again and again and it provides a transitive property and also resembles a real life relationship between classes so these are the advantages of using inheritance in Python guys so let me take a simple example to explain what is inheritance and how you can do it in Python so let's take it up to pyam guys and now I'm going to enter the presentation mode for better visibility so now what I'm going to do is I'll just take one class guys and and name it as parent let's say now give it a function so I'll name the function as function one and after that let me give it a statement let's say print function number one okay let's say this is a parent function now what I'll do is I'll take one more class guys and name it as child and for this in the Declaration I have to specify this parent over here this is also known as subclassing guys we do the subclassing because a child class is not able to identify which class it is inheriting the properties from so we do this by declaring the parent class inside the Declaration of the child class only now what I'm going to do is I'll just make one definition of a function let's say function number two and in this I'll give the print statement as let's say this is a child function now when we are declaring a child class it must understand from which class it is inheriting the properties from so we have declared the child class with the parent class in the Declaration and that's how the child class differentiate between a parent class guys so now to call the parent class methods we use the child class objects so what I'm going to do is I'll just make a object of the child class guys now to call this parent function which is the function number one let's see if I can do that and I'm getting function one and function two as well so I can call both the functions so first of all I'll call the function one and after that I'll call the function number two let's see what the output will be now the output is this is a parent function and this is a child function so basically what we have done is we have taken two classes named it as parent and child and from the child class we are inheriting the properties of the parent class here which is the function number one and this is the basic example of inheritance guys this is how you can do it now that I've shown you a simple example let's talk about the innit function in Python so what exactly is a init function init function automatically gets called each time an object is created for a class now when we add an init function to a parent Class A Child class will not be able to access the parent class method so to overcome this the child class init function overrides the parent class init function so now let's take a look at an example to understand this now to show how init function works let me first clear this we'll write a init function over here yes and instead of self I will add one more variable let's say F name and F age now what I'll do is I'll just write self do name is equal to F name and self. H is equal to FH now I'll take one more function guys so I'll just name it as let's say View and for view I want to print the value of f name self dot name and self. AG so this is my parent function guys and for the definition in the child class I will also make one init function so I'll just write it as init itself and again I have to add F name and F age and let's say self do name is equal to F name and self. H is equal to FH now this in function is going to override the parent in function guys so let's make one more function so this is going to be view as well and in this let's say I want to print okay before we move on we have to specify the parent function with the init function as well and we don't have to mention these variables instead I'm going to add one more let's say I want to add last name as well and I'm going to add it as let's say Eder now I'm going to print over here self do AG self dot last name and self dot let's say name all right I have to remove these let's make one more object and give it the value let's say I want the age to be 23 and last name is going to be python in the inverted commas name we have already specified so so we don't have to give it again and I'm going to just call the function let's see what happens what is the output will be so as you can see I'm getting the output as Python edura and 23 so this is how you can override the parent class init method using the child class guys so this is all about the init function now let's talk about the next topic that we have which is the types of inheritance so depending upon how many types of parent class and child class are going to be there inside the program following are the types typ of inheritance in Python guys so there is single inheritance there is multiple inheritance then there is multi-level inheritance hierarchial inheritance and there is Hybrid inheritance as well so we're going to talk about each of them in detail guys so first of all let's talk about what is single inheritance so when The Inheritance involves one child class and one parent class only it's going to be a single inheritance the example that I have showed you before is the example of single inheritance guys and talking about multiple inheritance it is going to involve more than one parent class which means we are going to have at least two parent classes and the child class is going to derive properties from both of them and this is called multiple inheritance now talking about multi-level inheritance let's say we have a single inheritance going on we have a parent class and we have a child class but the child class also act as a parent class or another child class that is going to be a multi-level inheritance guys and talking about hierarchial inheritance hierarchal inheritance actually involves multiple inheritance from the same parent class and talking about Hybrid inheritance if a program has more than one types of inheritance let's say we have a single and multiple inheritance going on simultaneously it's going to be a Hybrid inheritance guys so let's take a look at examples for each of them so let's go to pycharm guys and I'll remove all this so I'll start with single inhance guys so I'll just take a parent class and give it a function let's say function one and give it a statement let's say this is function one now let's let's take another class guys class child and give it the value of the parent class and after that we can move for another function let's say function number two and give it a statement let's say print this is function two now make a child class object and call the function so we can call both of these functions so I'll just call function one give it the output and we getting the output as this is function one so this is a basic example of single inheritance guys now talking about multiple inheritance what I'm going to do is I'm going to make one more class over here let's say class parent two now what happens here let's say give it a function number three let's say and print statement this is function three and in the Declaration over here I'm I'm going to just specify two classes and when I call the functions I can call function number one and I can call function number three as well guys so let's see what is happening here in the output I'm able to call the function number one and function number three as well from the child class object so this is the example of multiple inheritance guys now talking about multi-level inheritance so what I'm going to do is I'm just going to specify parent over here and from this let's say it doesn't have any Declaration of parent one which is this class so it is not able to inherit any properties from that but what I'm going to do is I'll just specify parent two over here and I can still call these functions because there is an inheritance going on between them which is multi-level inheritance which basically means this class the parent one class is actually giving properties to parent two class and parent two class is giving properties to the child class so this is example of multi-level inheritance guys now talking about hierarchial inher guys what I'm going to do is instead of parent two over here I'll just specify parent so for these two child classes I have the same parent class and now let's see if I can have the same output or not I'm not going to get the properties from the parent two because I have not specified it in The Inheritance so I'll just remove this and let's see what happens I'm getting the output as this is function one okay let's make the object for parent two as well all right give it one and and ob1 do let's say what functions we can have I can have the function number three and I can have the function number one as well so I'll just print function number one and from both the child classes I'm able to print the function number one so this is the example of hierarchial inheritance guys I'm using the same parent class to give the properties to both parent 2 and child class as well and now talking about Hybrid inheritance Hybrid inheritance actually involves more than one inheritance going on in the single program so we have a single inheritance over here so let's say I want to have multiple inheritance as well so I'll just specify parent two now and this is the example of Hybrid inheritance guys because we have a single inheritance going on over here and in the child class I'm inheriting both the parent one and parent two and this is the example of multiple inheritance so this is a Hybrid inheritance example guys okay we are getting a type error which is saying cannot create a consistent method resolution order for base parents parent one and parent two okay let's say instead of this I'll make one more class over here give it a value let's say parent number three give it a function function let's say four and print statement this is function 4 now instead of parent number two what I'm going to do is I'll just take parent number three guys and with the child class operator let's see if I can actually get the function number one and let's say I want function four as well I'm able to do that so in the output let's say what I get I'm getting the function one and function four so this is a simple example of Hybrid inheritance guys now that we done with the type of inheritances let's take a look at what all we have now so we're going to talk about the super function guys super function actually calls the parent class method directly so let's take a look at a simple example guys how it works so I'll just remove all this now what I'll do is I'll make a let's say parent class and give a function function one again the print statement now what I can do is instead of calling the parent function from the object I can just use the super function and over here I can just call the function one now I'll just print this is function two let's make a child class object now let me see if I can call the function two or function one I can do that so I'm going to call the function two guys let's see what the output will be so I'm actually able to call the function one directly from the super function over here so this is the function of super function guys it can directly call the parent method and now that we are done with the super function let's take a look at the next topic that we have which is method overriding in Python so method wring can also be achieved to change the functionality of the parent class function so let's take a look at an example to understand how we can actually achieve method overriding in Python guys so instead of naming them separately I'll just name them as same so when I create the child class Constructor and if I call the function now okay function one which is so when I'm calling this function technically it should call the parent function but what happens is it overrides the parent method okay okay to specify this run it again now I'm getting the output as this is function two even though I'm calling this function one which should be ideally calling the parent function but it is printing out the function which I have specified in the child class so this is how I have overridden this parent class method and this is how we can perform method overriding in Python guys let's take up another question which method is used to position the file object at a specific location in a file option A read option b seek option C tell or option D input please comment the right answer in the comment section below after learning about inheritance let's explore exception handling in Python you will discover how to handle errors and exceptions in your program why we need exception handling well to understand the concept let me quickly walk you through a very simple scenario consider the case where you're dividing any number by Z what will happen can you divide a number by zero you cannot correct but how would a kid approach this problem the kid would think that you can actually use regular division to divide something by zero so you're dividing something by nothing so it stays the same something like this right little does the kid know that this is wrong now check out how a programmer would approach the same concept well it is established that dividing by zero is not possible mathematically so as programmers we know it is not correct so this basically leads to two cases either an exception or an error so a Python program terminates as soon as it encounters an error well in Python an error can be either a syntax error or an exception and it is as simple as that well let us actually divide by zero for fun guys so this is what happens in python python presents us with this beautiful error message saying that it cannot divide something by zero well in fact let us head to pyam which is my ID for coding in Python so we can actually walk through this practically so guys here I am in my py charm so let me quickly go ahead and type out some simple code for you guys so let us start with yal to 10 we can actually print y by 0 now so let me quickly go ahead and run this in the console so as you can check out it says zero division error division by zero is not possible so you cannot divide anything by zero so let's establish that at this point guys that was good enough right so let's get started then let us quickly check out what exception handling actually is well guys to get a clear picture of what that is we need to start with understanding the definition for both exception and exception handling well what is an exception guys an exception is an event which occurs normally during the execution of a program that disrupts the normal flow of the program's instruction so instead of the program actually executing evenly and nicely there is actually a disruption in between the code so this we basically call as an exception so next what is exception handling guys this is this is the process of actually responding to An Occurrence of an exception as simple as that so basically the process of responding to the occurrence during compilation of exceptional statements which require special processing is actually what is exception handling guys so this is basically done because of the change in the normal flow of the program execution well it is a very simple concept and I'm sure at the end of the session you guys will agree well at this point what do you think of exception handling in Python guys head to the comment section and let me know what you think so we can interact there and now that we know what exception handling is we need to understand how the entire process of exception handling works so let us check it out first let us walk through what happens in Python so let us say the user makes an error what happens next guys when you think about it it is either the user that finds out the error or python will actually tell you what the error is correct so once you know what the error is and you know where it is you can basically start analyzing it to know if it is fixable or not well if it is fixable how can you go about doing that well if it isn't nothing to worry guys python is so good that no matter on what level you mess up there is always a way out of it guys so now if it's fixable how can we handle the exception check out the image on the right side so we need to First find the error if we cannot do it python will find out for us well next is to make sure you take caution while coding if you think that there is going to be an error in that particular piece of code well remember the word try at this point all right and later we'll actually fix the error and we call this as sketch just remember the keywords for now and we'll be walking through these in detail in the following slides in fact let us Begin by checking it out right now so Guys these are some of the important terms that you need to take a note of before starting to code and understanding exceptions so first we have try well try is basically the keyword which is used to keep the code segment under check so whatever code you put under try is actually the code under scrutiny guys and next we have accept well accept is a segment which is actually used to handle the exception guys so how do we know that the exception is occurred if our piece of code in the tri block has actually caused an exception then we can handle it in the except block and how do we use else well else is basically run when no exceptions exist guys and lastly we have finally finally we'll run even if there is an exception finally will run if there is not an exception as well so I want you guys to note this at this point of time and this will help you a lot in the coming slides guys so now coming back to python this is what it visually looks like we first have the tri block where we run a piece of code and next we have the except where the code actually runs only when there is an exception in the tri block and if there are no exceptions then we run the else block guys and lastly no matter what exception or no exception We Run The finally block always guys sounds simple right well it actually is and now that you're familiar with the process of exception handling let us check out how we can go about understanding this using python practically guys well syntax errors occur when the parser detects an incorrect statement well check out the tiny Arrow on the left side here well this is basically to indicate where the parser ran into the syntax error well in this particular example there were too many brackets right so there was an extra closing bracket well if you actually remove it and run it you will actually get a different error this time well check on the right side part of the code well this time you actually ran into an exception error well this type of code occurs whenever syntactically correct python code results in an error guys so the last line of the message indicated is what type of an exception error that you ran into well in this particular case it a zero division error and it says that the integer division or modul by zero is not possible so this is basically the same case that I showed you in pyam a while ago but instead of showing the message exception error python details what type of exception error was encountered well as I mentioned in this case it was a zero division error right well python comes with various built-in exceptions as well as the possibility to create self-defined exceptions as well and now that we clear with that let us check out how we can go about raising an exception on our own so we can basically make use of raise to throw an exception if a condition occurs the statement can be complemented with a custom exception well if you want to throw an error when a certain condition occurs using Ray you can actually go about it like the following piece of code you actually see on the screen and when you run this piece of code you'll be greeted with the following output guys so it says exception X should not exceed 5 and the value of x was 10 so let me quickly jump back to p Pam and we can execute this there so guys I'm in my pyam right now so I quickly typed out the code for you guys so let me quickly go ahead and run it and we can check out the error as you can see it says exception X should not exceed five and the value of x was 10 perfect right so let's quickly jump back to the presentation to check what's next so the program basically comes to a halt and displays are exception to screen right so this basically offers clues about what went wrong and now that we're clear with that we can actually proceed to checking out the assertion error guys so instead of waiting for a program to crash Midway you can actually start by making an assertion in Python well we assert that a certain statement is actually met and if this condition turns out to be true then excellent the program can continue but if the condition turns out to be false you can have the program to throw an assertion error exception for you guys well have a look at the following example on your screen well this is basically where it is asserted that the code can be executed in a Linux system guys so if you run this code on a Linux machine the assertion passes if you were to run this code on a Windows machine the outcome of the assertion would be false and what would happen well definitely the result would be something like this right so it would basically present us with an assertion error and says that that this code runs only on Linux right so I'm using a Windows just up in this particular case so let me quickly open up my pycharm and then we can actually run this piece of code to check out our exception guys so I'm back in my pyam and I've typed out the code guys so let me quickly go ahead and run this as you can check out since this is a Windows machine it says this code can run on Linux only but this particular case this assertion would be true if you were actually running this on a Linux machine guys so if any of you guys are using Linux machine make sure to try it out and on that note let's quickly come back to the presentation guys well in this particular example throwing an assertion error is the last thing that the program will do the program will definitely come to a halt and it will not continue guys but what if that is not what you want what if you want something different from this or that you want the program to continue while displaying an exception for you guys well now that we actually have a fair idea about how we can go about understanding exceptions let us Dive Right Into the Heart of exceptions now yes I'm talking about the try and except block guys so basically the try and except Block in Python is used to catch and handle exceptions well python basically executes code following the TR statement as a normal part of the program the code that follows the accept statement is the program's response to any exception in the preceding Tri Clause guys well as you saw in the earlier example that I actually showed you when syntactically correct code runs into an error python will throw an exception error and this exception error will actually crash the program if it is unhandled guys so the except Clause determines how your program responds to these exception guys so instead of actually crashing our program we can actually tell python what to do when this particular exception occurs we'll check out the following function guys so this function can basically help us understand the try in the except block while the Linux interaction function can only run on a Linux system the assert in this function will actually throw an assertion error exception if you're using it on any other operation system apart from Linux well we can actually give this a try in py Cham so let me quickly open up that so guys I'm quickly here in my py Cham so let me quickly go ahead and select this and run it well this won't say anything right now because well if it was actually a Linux platform the message would have been printed right so let's quickly jump back to the presentation so basically if we run the tiny piece of code you see on the bottom the way we actually handle the error in this particular case is because we gave out a pass right well if you were to actually run this code on a Windows machine you would get the following output which is already on your screen right so it is a blank output you get nothing well the good thing here is that the program actually did not crash but it would be nice to see if some sort of exception occurred when you actually ran your code well to this end you can actually change the pass into something that would generate an informative message like this check it out so let me quickly go ahead and run this in pycharm well as you can check it out it says the Linux function was not executed right so basically this happened because I am on a Windows machine guys so let's quickly go back to the presentation and guys when an exception occurs in a program running this particular function the program will continue as well as inform you about the fact that the function call was not successful well what you did not get to see was the type of error that was actually thrown as a result of this function call guys so in order to see what exactly went wrong you would need to catch the error that the function threw well check out this particular piece of code I have for you guys so here is basically where we actually capture the assertion error and we print the output message to the screen so we have a tri block we have the same function and we have accept as error right so we're going to print what type of an error it is followed by a message for us right so running this particular case on a Windows machine will actually give us this following output guys so it says function can only run on Linux system and whatever you have chosen in the print block is actually being printed for us so let me run this in pycharm so as you can check it out we have the message print right so it was the same as I told you so it was the same message as I told you before heading back to the presentation well in the previous example we actually called a function that we wrote ourselves right and after that when we actually executed the function we CAU the particular assertion error exception and then we printed it on the screen well I have for you another example where you actually open a file and use a buil and exception guys in fact let us dive into pyam and we can actually run this and we can come back and take a look at the output so guys I actually came into a py Cham and I actually ran that particular piece of code why does it say could not open file log well guys basically if the file. log does not exist the block will give you this output right so it says the file could not been opened well this is an informative message and our Python program is actually still able to continue to run it is not crashed right well actually in the python documentation you can see that there are a lot of buil-in exceptions that you can make use of and here is one exception that I have for you guys that you can check it out so it say exception file not found error right so basically this is raised when a file or directory is requested but that doesn't actually exist and this is just one among many that python offers to us guys well to catch this type of an exception and to print it on the screen we would actually use this following piece of code guys so in the tri block we actually going to open it as file and we're going to read something present in it guys we're going to accept it by pushing a file not found error as an object and later we actually end up printing that object right so let me quickly go into pycharm and we can check it out well as you can check it out we have error number two which says no file or directory right so it's perfect well you can have more than one function call in your Tri Clause actually guys and anticipate catching various exceptions as well well a thing to note here is that the code in the tri Clause will actually stop as soon as an exception is encountered but there's one important thing that I want you guys to note down is that while catching an exception it basically hides all of the errors guys well definitely there are some unexpected errors in your program right when you're catching an exception and even these are completely hidden from you well this is why basically you should avoid using bare accept statement Clauses in your python programs guys so instead basically what you can do is you can refer to the specific exception class that you want to catch and then handle those particular exceptions guys so look at this following piece of code I have for you so here basically you first call the Linux interaction function and then later actually try to open a file guys so let us quickly jump into pyam and we can actually check it out so as you can see I actually executed the program guys again then if the file doesn't exist running this code on a Windows machine we'll give you that output right so it basically says that the function can run only on a Linux machine and then we have actually printed something guys well what we actually did here is inside the tri Clause we directly ran into an exception immediately and we did not get to the part where we actually try to open our file. log right now basically when you actually run it on Linux machine it's going to says no file or directory found check it out here guys so this is the windows output that you get and this is the Linux output guys well at this point let us take a Qui quick break and check out what are the key takeaways of this particular module guys so basically a tri Clause is executed up until the point where the first exception is encountered and inside the except clause or the exception Handler what we basically call it we can actually determine how the program actually should respond to that particular exception and we can actually manipulate multiple exceptions and differentiate how the program should respond to each of them right and lastly we actually learned why we should avoid using bare except Clauses guys and now that you're clear with this next up I have for you is the else Clause guys so basically in Python using the else statement you can instruct a program to execute a certain set of code only in the absence of exceptions guys well check out this following diagram on your screen so basically in the Tripod we have the code except when we actually want to handle the exception or else in case there is no exception we're going to run the piece of code that comes in under else guys so let me quickly walk you through the code guys so here is basically the same Linux interaction function and we have an assertion error here and we actually are going to print the error right so else if there is no assertion error so we're going to have an else clause and we're going to print saying executing the else Clause right so let me quickly open up my pyam and we can run this piece of code guys so as soon as I go ahead and run this it says function can only run on a particular Linux system right so as you can check out the output it says the function can run only on Linux systems right so in this case I have a Windows machine so we actually not printing the except Clause here but if you were running this on a particular Linux machine this is the output that you would get guys so it says doing something and executing the else Clause correct this happened because the program did not run into exceptions any exceptions right so else Clause was actually executed well you can actually try to run the code inside the else clause and catch possible Exceptions there as well well again we have the same Linux interaction here we're going to print it right so the Linux output says doing something and no such file directory found well this is basically for the else clause and we're using the same file example here but then we're actually trying to catch an exception in the else block as well so the output is pretty much straightforward as well right well from the output you can actually tell that the Linux interaction function actually ran well because no exceptions were encountered an attempt to open file. log was actually made and that file did not exist and instead of opening the file you actually caught the exception which is the file not found exception pretty simple right and I hope you guys are clear with all of the concepts that we discussed until now and next up we need to check out how we can actually use the finally Clause guys well to begin with imagine that you always had to implement some sort of action to clean up executing your code guys well python basically enables you to do so using the finally Clause have a look at the following example guys check out the workflow on your screen I'm pretty sure we all familiar with try except and else at this point of time right so this is the chronological order that you need to go into first we have the try to check for an exception then we actually handle if there is an exception using the except or else if there is no exception we're going to print whatever is there in the else block and lastly we have something called as finally guys so no matter what we're going to execute this in case if there is an exception the finally block is going to run in case there is no exception finally block is going to run there as well so let us quickly check out a coding example guys so basically this is the particular code I have for you guys and let me jump back into my pycharm and we can actually execute this so guys I'm back into my py Cham so let me quickly go ahead and run this well as you can check it out it says that the function can only run on Linux machine this is because I'm on a Windows machine right now and no matter what right so exception or no exception we have this message which is cleaning up irrespective of any exception guys so this is basically the use of finally guys and that is as simple as it gets so it's pretty much simple right well try accept else finally all of this is a really simple concept and once you understand what it actually does you can go about doing a lot using python guys well no matter what the python application is there is a very good chance that you'll actually make use of exceptions guys let's try another quiz question what is the function of the sqi tree module in Python options are option A to Generate random numbers option b to handle Json data option C to interact with SQ L databases option D to perform mathematical operations please comment the right answer in the comment section below now that you know how to handle exceptions we will explore request in Python this topic will teach you how to make HTTP requests to interact with web services what is python requests requests in Python is a module which can be used to send all kinds of HTTP requests it is very easy to use and has features like passing parameters in the URL and passing custom headers as well it is a humanfriendly HTTP Library as it also suggest on the official documentation page as well and it is one of the most downloaded python Library with more than 400,000 downloads every day so you can imagine the popularity of python request guys it was written by Kenneth rites and has a license under Apache 2.0 so this is about python request guys I hope you are clear with what exactly is python request so now that we have learned what is python request let's take a look at the advanced features that python requests come with so first of all we have keep alive and connection pooling and then we have Elegant key value cookies then coming on to the next one we have international domain Mains and URLs and automatic decompression as well and then we have sessions with cookies persistence and unicode response bodies then we have browser style SSL verification and https proxy support as well there is automatic content decoding and multipart file uploads and then there is basic authentication and streaming downloads as well and last but not the least we have connection timeouts and chunk requests so these are all the advanced feature guys don't worry we'll be learning about how we can use python request so let's talk about why exactly do we need python request or why are we using python requests so the reason behind this is pretty simple guys we use Python request because you don't have to manually add the queries to your URLs and form encode post data and that is a reason enough to use Python request guys and if you're not able to understand this reason behind using the python request you'll be able to understand this later on in the session when I'll be showing you the use case so hang in there now that we are done with the reason behind why we are using python request let's try to understand how you can install python request on your system or on the project that you're working on so first of all you have to install the PIP environment on your system and then you have to run this command that I'm going to tell you inside the terminal which is PIP install request guys so let's take it up to pycharm and I'll show you how you can install request on your project or on your system guys now as you can see I have a new project over here inside pycharm so I'll show you guys how you can install request on your system so you have to open the terminal here just write pip install requests and you will see that the files are being installed here it will take some time guys and there is one more approach to this if you're using py charm you can open the settings and inside the settings you will find the project interpreter and over there you can simply add the request library and that will do the job for you guys it is same as running this command inside terminal okay I'll show you that as well so you open settings and here you will go to the project where you will find the project interpreter and over here you can simply just add your file let's search requests here and this is by author Kenneth R that I have told you guys so I'll just install this package and it will not take so much time because we have already installed it and as you can see we have request over here inside the so you can see request over here which has all the files and everything for our project so I'll just type okay close the terminal and over here I will make one demo file guys to show you how you can make get and post request so we have this file let's enter okay let's first of all talk about making get and post request guys so we have installed request on our system guys so let me talk about get request what exactly are they used for and how are we going to use them inside the tutorial I'm going to show you or the use case as well so get request are basically used to request the data from the server so what you have to do is I'll show you the syntax as well so you just have to import the request library and then you will have to make one response object in which in this case r is the response object and you are going to use the request library and make the get request and inside the get function you have to mention the URL that you're going to make the request from so let's take it up to py Cham guys I'll show you how you can make the get request so let's enter the presentation mode for better visibility so I'll just import the request Library yes and I'll make one response variable or response object and inside this I will use request.get and inside this I will have to specify one URL guys so I'll just show you what URL I'm going to use so what I'm going to do is I'll just copy the URL over here and when I make the print statement I will use the response object and let's get the text over here using the response object whatever we have on the server and when when I run this I will be getting the text for this URL that I've just provided as you can see over here so this is how you can make a get request guys now let me show you how you can actually pass parameters inside your url also so what I'll do is I'll just make one variable let's say payload and inside this I will specify a dictionary with some values let's say key one and value one okay so when I pass this inside the get function with the parameter that is params is equal to that is the parameter variable guys so I'll just pass payload over here and when I get the URL now I should be getting this parameter that I have just passed inside the URL so you will be getting this dictionary of the value that I have just passed as a parameter inside the URL so this is how you actually pass parameters inside your url guys while you're making the get request similarly you can also pass custom headers as well I'll be showing you that later on in the session so we have talked about making get request guys so let me just talk about about how you can make the post request as well so we'll talk about what exactly post requests are used for so basically post request are used to submit the data to be processed to the server so let me show you an example with the syntax first of all you have to import the request library and then you have to use the post function as well using the request keyword after that you have to mention your URL and the data that you want to give it as a payload or something like that and then you have the response variable as well or response object so let me take it up to py Cham guys you be able to understand this better in py charm so instead of get request we'll get post over here and instead of parameters we'll just pass this as data so instead of uh text okay we'll just get the text again so let's see what are we getting so we don't have post request allowed inside this so instead of get we'll just write post over here run it again as you can see so we have this dictionary that I added using the post request Guys these are the headers and and then we have cookies as well no we don't and this is how you can actually make a post request guys I hope you are clear with making the post request and get request guys so this is all about making a post and get request guys also I want to show you what are all the content or the response content that you get using these requests so let me just take one response object again I'll make a get request so I'll just pass the URL over here and we're good to go so we will print whatever we'll get so using the response object let's see the content type or what all content we can get so we can get text we can get headers cookies and then there is status code let's check the status code first guys if the status code is 200 we are good to go it is 200 guys so we'll get some more content from this so we'll get cookies now it will be showing us the cookies inside our cookie jar yes we are getting the cookies inside the cookie jar and we can also pass our own cookies I'll be telling you about that later on in the session don't worry guys so then there is headers as well you'll see all these headers inside a dictionary guys so this is how you actually access the headers inside uh URL and then there is the content format also you can get the content in the format of Json as you can see we're getting the content as Json objects so this is all about response content guys now let me get to the next topic that we have which is cookies and headers guys so I've just shown you how you can get the cookies and headers inside using the response variable so let me just talk about what are cookies and headers guys so we can view the servers response headers using a python dictionary which I have just shown you guys so the dictionary is special though it just made for the HTTP headers and similarly you can get the cookies as well if a response contains some cookies you can quickly access them and to send your own cookies to the server you can just use the cookies parameter and cookies are returned inside a request cookie jar which acts like a dictionary but also offers a more complete interface suitable for over multiple domains or parts so let's try to understand this inside py charm guys so what we'll do is we'll just get some cookies here and when I run this we getting a cookie job okay guys what I've done is I have actually changed the URL so what I'll do is I'll run this command now and you will be seeing the cookies over here which is inside the deest cookie jar and what I can do is I can also pass my own cookies so I'll take a variable name it cookies and give it a dictionary guys and inside the dictionary I'll specify some values let's say key1 is equal to Value one and then over here using the cookies parameter I will just pass cookies here so I'll just write text over here and when I run this I should be getting a dictionary with the cookie jar which actually has the cookies named as key 1 and value one so this is how you can actually make your own cookies inside a web server and then I'll show you what you can do with headers as well so let's get the headers here when I run this I should be getting the headers inside this URL which are all these headers over here inside the dictionary so this is how you can actually access the headers inside the URL guys so let me talk about session objects guys which is the next topic that we have so session object actually allows us to persist certain parameters across request so it also persist cookies across all request made from the session instance and we'll use the URL Library 3 Connection pooling and if you're making the several request to the same host the underlying TCP connection will be reused which can result in a significant performance increase and also a session object has all the methods of the main request API as well so let's try to puras some cookies across the request guys so we'll move to the pycharm again so we have come to the pycharm now what I'll do is I'll make one variable let's say session object that is so I use request do session and after that I'll just use a get statement where I'll just use s. getet pass the URL and we're good to go then what I'll do is I'll make a response object and inside the response object I will pass one more variable or URL which is this one now what I'll do is I'll just print response. text let's see what happens as you can see we have persisted one cookie so this was all about session objects guys and any dictionaries that you pass to a request method will be merged with the session level values that are set and the method level parameters override the session parameters as well and you have to consider that method level parameters will not be persisted across request even if making a session as well so now that we are done with session objects let's take a look at errors and exceptions that we have for python request guys so first of all in the event of a network problem for example a DNS failure or a refused connection request will raise a connection error exception and it will raise a HTTP error if the HTTP request returned an unsuccessful status code which is actually 405 or 404 as well now if a request times out a timeout exception is raised and if a request exceeds the configured number of Maximum redirections a too many redirect exception is raised so this is all about errors and exceptions that we have in Python request guys so now that we are done with errors and exceptions let me talk about a small use case that I have made using the Jango app so we will exit the presentation mode over here and I will open the project that I had made so as you can see I have ajango file over here with all the init settings.py urls.py so I have over here the URL configurations and everything and I have a views.py file inside my app that I had created so this has the code for making a request to a web API and inside that I will be able to search for a particular City and I will be getting the description of the weather and the temperature over there and the condition of the weather over there so I will show you this and this is my template guys so let me run the server guys and if you're wondering how you can actually make a web app I suggest you check out the Eda tutorial for D Jango web applications where you will be able to learn how you can make a web app from scratch guys so when I run my server I should be getting a URL guys so that's where I have to actually make the request so as you can see I have a city London over here specified first of all so when I open this first of all I have a heading which is saying what is the weather like then I have the icon which is saying it has broken clouds then there is London city name and the temperature in fahrenheit so let's see if I can do that since I'm making request to the API when I change the city over here I should be getting the temperature of the city again so when I refresh this now as you can see I've changed the city as well but I'm getting the temperature of the city that I have just specified guys so as you can see how easy it is to make request to a web server and get these values so I'm making this request to this URL guys which I have specified over here open weather map API this provides us the API and I'm able to search for cities over there inside the request that I'm making and this is how you can actually make a simple Django app for calculating or getting the weather of a city using the request Library guys and the next question is what is method overriding in Python inheritance option A a superclass method hidden by a subclass method or option b a subclass method with the same name as a superclass method option C a method changing behavior of a function or option D a method deleting an attribute so please comment the right answer in the comment section below you have learned about HTTP request so let's move on to the date and time in Python here you will discover how to handle and manipulate date and time data let's take a quick look at the time module and its built-in methods the time module consists of all time related functions that are required to perform various operations using time it also allows you to access several types of clocks required for various purposes the time module begins recording time from the epoke epoke literally means a time in history and it begins on 1st January 1970 as you can see on the screen I've listed down some of the most important functions that are available in this module so talking about the first function which is time it Returns the number of seconds that have passed since the epoke the C time method Returns the current data and Time by taking the elapsed seconds as its parameter sleep tops the execution of a thread for a given period of time the local time method Returns the date and time in the struct time format by taking the number of seconds passed since the epoke as the parameter GM time on the other hand Returns the current date and time in the UTC format the MK time method is inverse of local time it can take a tuple of Maximum 9 parameters and Returns the seconds pass since the epoke and finally the ASC time method which can also take up to 9 parameters and returns a string representing the same okay so now I'll jump on to my Jupiter notebook and show you all how this works so the first thing that you'll have to do is import the time module so I'll say import time and I'll hit Run Okay so first I'll be making use of the time method present in the time module so I'll just say time. time and I'll hit run so like I've already told yall this method Returns the number of seconds that have passed since the epoke so I'll hit run okay so here is the number of seconds that have passed since the epoke now if I want to convert it to the current date and time I can make use of the C type method so I'll just have to use time. ctime now if I want to convert this into the current date and time I can make use of the C time method to do this I'll just use time do c time and I'll have to pass the number of seconds as a parameter to this so as you all can see on the screen I've passed the number of seconds which was returned by the time method to the C time method and I've got the current date and time if you want more information about these functions and methods all you can do is use the help method so I'll just say help time and if I want to fetch data about the time method I'll just say time. time and I'll hit run so as you all can see it says that this method Returns the current time in seconds since the epoke similarly if you use help on any method or function it will return the corresponding information about that function okay so moving on I'll be making use of the local time method and see what it returns so I'll just say time do local time and I'll hit run so as you can see on the screen I've got the current date and time in the struct time format now to make youall understand what the struct time class is let me get back to my presentation okay so as you all can see the stru time class basically has nine attributes starting from the year who value starts from zero and goes up to 99,999 the second attribute is month whose value will be anything from 1 to 12 after that is mday which means the day of the month and the values can range anything from 1 to 31 similarly hour minutes and seconds have the values 0 to 23 0 to 59 and 0 to 61 the weak day value can be from 0 to 6 where 0er is Monday y day or your day can be any anything between 1 to 366 and the final attribute is daylight saving time it's 1 if it's summer zero if not and minus one if unknown okay now that you're aware of what this struck time format is let's come back and see what our output actually means year is 2019 month is 8th or August the date today is 8 as well and so on so I hope you're clear with this okay so now in case you want to fetch the number of seconds that have passed since the epoke so to do this you can make use of the MK time method okay so all I'm going to do over here is first store the local time in a variable say a and after that I'll take another variable B wherein I'll be using the MK time method and I'll pass the parameter to it as a finally I'll just print out B so as you can see on the screen the MK time method has returned the number of seconds that have passed since the epoke till now so now in case you want to fetch the current date and time from the struct time format and return it in local format you can make use of the ASC time method so like I've already told you all before the local time method Returns the current time in the struct time format I'll be using the variable a which stores the struct time format of the current date and time to convert it to the local format and to do this I'll create some new variable say C and then I'll use ASC time method so time. ASC time and I'll pass the parameter to it as a and then I'll just print out C okay so as you all can see over here it has taken the struct format and has returned the local format of date and time python also allows you to format and pass strings using the S strf time method and the STP time method the S strf time method can take a tuple containing nine parameters and returns a string representing the same depending on the format code used the St strp method passes a string and returns it in the struct time format to show youall what these format codes are I'll just use the help method and I'll pass time. sdrf time as a parameter to this and I'll hit run oh I've made a spelling mistake over here sorry guys it's s strf time so as you all can see over here I have a number of format codes which I can use to format my date time strings okay so first let's make use of the S strf time method so as we all have seen I've created a variable a in which I've stored the current time in the stru time format so let me just print this out again okay so now I want to format this output in a manner which is convenient for me so to do this I'll use the S strf method so I'll just say time I'll take another variable say x is equal to time St strf time I'll use the St strf time method within which I'll be using the format codes to format the date as per my choice so first I want to print out the month so I'll use the format code mod M it's small M guys please be careful because this is case sensitive and then between this I just want to see a slash after this I'll just print the date I'll use mod D and then the year so I'll use mod Y sorry for the the spelling mistake I'll just print X so as you can see on the screen I've Returns the current date in the month day year format similarly you can also pass a string and return it in the struct time format to do this you can make use of the St strp time method to do this I'll take another variable say Y and I'll pass a string to this I'll say 8th August 2019 and then I'll make use of the S strp method to pass this string so I'll just say time. sdrp time and I'll pass y as a parameter to this and the format of it which is day month and year capital b means the full name of the month and now hit run okay so as you all can see over here I've passed a string using the Str strp method and returned it in the struct time format so now let's get back to our presentation and take a look at the date time module the date time module is similar to the time module consisting of all the required methods that are essential for working with date and time some of the important methods present in this module are the date time method which is a con structor and it consists of two methods which is today and now that will return the current date and time the date method will help you create a date and the time method will help you create time which includes hour minutes seconds micros seconds and the time zone information the datetime module also consists of a from stamp method which converts the seconds to return the corresponding date and time another very important function that's present in this module is time Delta time Delta basically returns a duration which will be the difference between two different times okay so now let's get back to our Jupiter notebook and see how this module actually works I'll just create a heading over here say date time and I hit run the first thing that I'll have to do is import this module so I'll say import date time after this I'll be making use of the date time Constructor to create some date so I'll say date time and then I'll pass some values to this starting with the year which is 2019 and the month as 6 date as 7 time as 4 minutes seconds and milliseconds and then I'll just print this out so as you can see on the screen I've created some random date using the date time Constructor now in case you want to fetch the current data time all you can do is use the today and the now methods like I've already told you all previously so I'll say date time so I'll just copy this and then I'll use the today method so as you can see over here it has returned the current date and time along with milliseconds which is very precise I can also use the now method instead of today method over here so I'll just say now and I'll hit run so as you can see both these methods return the current date and time now in case you want to access some particular value from this date all you can do is use the attribute name to access that particular value so in case I want to access the year and the month all I can do is save this into a variable say V and then I can use v.e to access the year so as you can see I've accessed accessed just the Year from the current date similarly you can access anything of your choice so if I say print v. month and then I'll say print v.r and I'll hit run so as you can see the month and the hour have been returned similarly you can access any values of your choice using these attributes now in case you want to set only date without time you can use the date method so you just say date time do date and then pass the date as a parameter the time method can be used to create time without date so I'll just say it's 3 hours 45 minutes and 23 seconds so now moving on towards time Delta which is a very important method that's present in this module like I've already told yall this method represents a duration which can either be the sum or the difference between two different dates now to make use of this method I'll just take some variable say B1 and I'll say date time do time Delta and I'll pass the number of days as 20 to this you can also pass other parameters like micros seconds minutes Etc okay I'll take another variable say B2 and I'll use the same method again and to this I'll pass the number of days as 30 now I'll take another variable say B3 within which I'll just store the difference of B1 and B2 so I'll say B1 minus B2 and then I'll print what is B3 and the type of B3 so as you can see over here the difference between B1 and B2 is minus 10 days and the time since I've not specified anything is zero and the type of B3 comes under the time Delta class after covering the date and time let's talk about python regular expression you will learn how to use regular expressions for pattern matching and text processing why exactly we use regular Expressions we are going to focus on various problems that regular Expressions helps us to solve so this is the first problem guys so over here what happens you have a log file and from that log file you want only date and time and as you know with the format of the log file is not understandable to everyone so here's a guy who only wants date and time from that log file so what he can do he can make use of regular Expressions identify the pattern and he can actually get the date and time for that particular log file so this is the first problem we'll see a lot of more problems which IR regular Expressions help us to solve so we'll move forward and we'll see the second problem now this is the second problem that it helps us to solve imagine yourself as a sales person and you have a lot of email addresses and many of them are fake so what you can do you can make use of regular expressions and all the email addresses have a particular pattern they have a format so with the help of regular Expressions you can verify that format and you'll get to know what all email addresses are correct and what all email addresses are fake ones so as you can see obviously s.com is a fake email address so using the pattern that is there in all the email addresses you can verify whether that email address is correct or not with the help of regular Expressions all right so let's move on and see what are the other problems so this is the third problem that it helps us to solve we'll take the same sales guys example that we have taken in the previous slide now over here that guy has a data of various customers phone numbers and we know that a lot of time people don't give the correct phone number because nobody wants a sales guide disturbing them at our timings right so that salesperson has a problem he wants to know that what all phone numbers are correct and what all phone numbers are fake so every correct phone number will have a particular pattern or a format so using regular Expressions he can identify what all phone numbers are correct and what all phone numbers are wrong and at the same time different phone numbers that belongs to different countries or different location will have a different format so again taking that thing into consideration he can again use regular expressions and identify to which area it belongs to now in this particular example what I've shown you is I've shown you two geographical areas one is India another is USA so with the help of regular Expressions you can actually find out what all phone numbers belong to USA and what all pH numbers belong to India so I hope this is clear to you so this is the fourth problem guys now over here what happens you have a student database and that contains name age address now what happens there are a lot of students who live in a particular area and the area code of that area is 596 but what happened the area code has been updated and it has become 5976 now if you go manually update that for all the students that'll take a lot of time so instead of that what you can do you can make use of regular expressions and find out all the area codes from the student database and after that you can replace it with the updated area code or the PIN code so as you can see with regular Expressions you can even replace a particular string we'll move forward and we'll see one more reason of using regular expression so now this is one more reason to use regular expression because even if you don't have a python background if you have any other programming background like Java PHP C gruy Swift Ruby you can use regular Expressions because it is compatible with all of these programming languages and it is even compatible with JavaScript although it is not written here but yeah it is even compatible with JavaScript so till now we have seen various reasons to use regular Expressions but I know you guys must be wondering what exactly regular Expressions is right so don't worry guys we'll move forward and we'll see what exactly regular expression ex is so a regular expression is basically used for describing a search pattern so you can use regular expression for searching a specific string in a large amount of data you can even verify that that string has a proper format or not you can find a string and replace it with another string and you can even format the data into a proper form for importing for example so these are all uses of regular Expressions now over here I've shown you an example here there's a string which is present in which they have written Janice is 22 and Theon is 33 Gabriel is 44 and Joe is 21 so as you can see what all useful data that I can find from here only name and age I don't want the rest of the things that are present in this string so what I can do I can identify a pattern and with the help of regular expression I can convert that to a dictionary and in that dictionary only the name and age will appear now my question is to you all guys can you identify a pattern in order to get the name and age just give a guess you just need to identify the pattern all right so Sarah says all the ages are in the form of integers all right Sarah that's a very nice observation but what about the names all right so I've got a couple more answers and they say the same thing that the age is represented with the help of integer numbers so you can get the integers for the name they have no idea how to get it don't worry guys it's totally fine just give a guess all right guys so let me tell you so basically if you notice that every name starts with an uppercase first letter so the first letter of all the names is an uppercase letter and when we talk about age all of the age are represented in numbers so what you can do with the help of regular expression you can actually find out the two-digit numbers and at the same time you can find out the words that starts with an uppercase letter and then it goes on to lowercase letters and the star actually represents all of them so you don't need to worry about the syntax that is there in front of your screen I'll be actually explaining you these things in detail so you don't need to worry about that so I hope you have understood the pattern that I'm telling you all right so we have a question from Devon he's asking what if this may contain a name of a place all right Theon so this string does not contain a name of a place that's all I can say right now if there was a place present here then we have to look for a different pattern at that time so basically with regx you have to make sure that you identify the pattern for the string that you want so it is very important so let us move forward and I'll open my py charm and I'll tell you how to get age and name all right so let's do it so this is my pie charm guys so over here what I need to do is I need to First import the module for regular expressions for that I'll type import re and now I'm going to type in the string that was there in the example so I'll type in name age equal to and now I'm going to write it Janice is 22 and Theon is 33 now the next line I'll write Gabriel is 44 o I forgot the space and Joey is 21 now close it so now for age I'm going to type in ages equal to now you don't need to worry about the syntax that I'm going to write I'm going to tell you all these things in detail so this is just an example that I'm giving you that with the help of regular expression you can actually get the name and age after that I'm going to discuss each and every operation in detail so what I'm going to type in you don't need to worry about that I'm just showing you that you can actually do it I'm just giving an example re. findind all are one comma three because all my ages are two digits are of two digits and then write the name of the string and for names what you going to do you're going to type in names equal to similar to that re do findall R and my first letter is an uppercase letter that is between a to zed after that I have lower cases so I'm going to type in A to Z in lower cases and then I'm going to put in a star that will actually include all those and finally the name of that string that is name H now what I'm going to do is I'm going to Define a variable and I'm going to name it as age dict equal to curly Braes let's keep it empty right now and now one more variable I'm going to Define that is X is equal to zero now I'm going to use a for Loop I'll type in for each name in names age dict each name ages x x + = 1 now print this age dict yeah so if you're not able to understand what exactly for loop is and what are dictionaries so you can go and watch the previous tutorial videos on Python and then come back again now let's go ahead and execute this so yep you have got the dictionary that includes only name and age of that person so what I've done here is what is a pattern I'm repeating it again so for all the names the first letter is an uppercase letter and all the ages are expressed in terms of numbers so using that pattern I have got only name and age so this is just an example we'll actually see how to perform various operations using regex or regular Expressions so I'll go back to my slides now let's move forward and understand the cursor operation of regular expression so basically in both strings and regular expression both of them have their own cursor so what happens is suppose you are searching for R and your regular expression includes R so your cursor is at R in the regular expression but for text it'll check for B it is not equal to R then e then e then again when it comes to R it will see that this is what you are searching so it'll stop right there the moment you search for S it'll go on and it'll come towards s and same goes for n as well so this is a pretty basic operation but it will really help you to visualize how things work with regular Expressions so we'll move forward and we'll look at various operations that you can perform with regular Expressions so first we'll find a word in a string so we have a string that says we need to inform him with the latest information and we need to find the word in form so let us go ahead and execute this practically I'll again open my py charm so this is my py charm guys let me just first clear it so let's begin by importing our regular expression module so for that I'll type import re and now we have a sentence and we want to find a word in form there so what I'll do I'll just type in if re. search in form and our string is we need to inform him with the latest information so this is our string give a colon and now I'm going to type in print there is in form so let me tell you what I've done here first I've imported the regular expression module and after that I've defined a condition which says that if it is able to search in form in this particular string that is we need to inform him with the latest information then it'll print there is inform otherwise it won't print anything so as you can see that inform is present here so it should print there is in so let us go ahead and execute this so yep you can see that it has printed there is in form now let's be more specific and suppose we want to find all the matches here so let's write a method that will do it for us so for that I'm going to use find all which will return a list of matches for me so for that what I'm going to do is I'm going to write in here let me first remove this and now what I'm going to do is I'm going to write in all in form which is nothing but a name that I've given you can give whatever name you want ar. find all and I've told you earlier as well find all will return a list of matches now over here what I need to find I need to find in form from which string the string is we need to inform him with the latest information all right guys and so now I'm going to type in a for Loop which says that for I in all inform give a colon print I that's it so now what I've done here you can see that I've imported the regular expression module then I'm using find all in which it will return all the matches and what I'm finding I'm finding inform and from which string I'm finding inform this is the string that I'm using and I finally I've used four in order to find all the matches so let's go ahead and execute this so yep it has found in twice because you can see that it is available here as well in and even information over here you can see that inform is present so this is how basically you find a word in a string by the help of a regular expression so let me first go back to my slide so we have seen how to find a word in a string next we are going to understand how to generate an iterator so basically what I'm going to do is I'm going to get the starting and the ending index for the word that I'm searching over here I'm searching inform so it'll give me the starting as well as the ending index for all the matches that it finds so let us go ahead and execute this practically I'll open my pie charm once again let me remove all of this and over here I'm going to Define a string so what I'm going to write here is I'm going to write here we need to inform him with the latest information yeah so now what I'm going to do is I'm going to generate an iterator by using find iterator and it is going to return the iterator of the matching objects so basically I'll be printing the starting and the ending index of the matching object object so for that I'll use the for Loop so I'll write in for I in re. find iterator and I want it for inform so I'll just type in inform and now I'm going to type in the name of the string that is Str Str colon now I want that to be converted into a topple so for that I'm going to type in log toop equal to I do span and finally print lock top so basically it will print the starting and the ending index of the matching object so let us see if it does that so yep so as you can see that for inform the starting index is 11 and the ending index is 17 for information it starts with 38 and ends at 44 so this is how you can actually generate an iterator by using find iterator and this will return the starting as well as the ending index of the matching object so if you have any doubts you can write it down in your chart box it's pretty easy guys so we'll move forward and we'll have a look at the other operations that you can perform with regx so now what I'm going to do is I'm going to match words with a particular pattern so we have a string in which we have sat hat mat and part so now my question is to you all guys what is the pattern that you can see in this particular string that is sad hat M and Pat so let me go ahead with it and I'm going to show you how you can match words with a particular pattern using regex so first I'm going to open my py charm let me remove all this so let me Define a string once more I'll type in s strr so we have sat Matt hat Matt and we have Pat this is our string now I want to match anything that ends with at so for that I am going to Define a variable all Str Str and now I'm going to do is re. all now what I want I want words that starts with S H M and P all right and after that it should end with at so I've written at it's very simple guys and now what I'm going to type in I'm going to type the name of the string that is Str Str so this bracket where I've written shmp it shows that I'm matching specifically for the words that starts with S H M and P now now I'm again going to use a for Loop in which I'm going to type in for I in all string give a colon print I it's that simple go ahead and execute this and see what happens so yep it prints hat mat and Pat but one thing to notice here guys it will not print sat why it is not printing s because it is an uppercase letter so if I go here and I make it as capital X and go ahead and execute this so yep you can see that even sat has been printed so let me go back to my slides and see what all other operations that we can perform with regular Expressions now over here what I'm going to do is I'm going to match series of range of characters now what does that mean let me explain you with the example that is there so now what I want here is I want all the words in which the first letter is between the Range s to M so all the words whose first letter comes in the range H to M should be printed and it should be ending with at so basically it should print hat and Matt because P comes after M so does s so it won't print satin part now let's go ahead and see in our py charm whether this happens or not now over here what I'm going to do is I'm going to remove this s so it do p throw in a hyphen here and execute this so yep it has printed hat and mat so if I want all these things to be printed what I can do is I can write in here Zed and execute this so yep it has printed hat mat and part but it has not printed s why because it starts with an uppercase s so if I make it as s and I'm going to print this so yep it has printed sat as well because between H to Z all s h and M and P lies so it has printed all the range of characters whose first letter is present in the range HED to Z so now I can use a carrot symbol that will include all the words apart from ones which have the first letter between the range H to M so let me first make it as M and now I'm going to use a carrot symbol yeah so when I use this carrot symbol this means everything apart from this range that is H to M go on and execute this and you can see it has printed sat and Pat but not hat and mat because of the carrot symbol that I've just shown you right so I hope you all are clear with how to actually find a range of characters in a string and now what I want I want to replace a particular string so as you can see in the example I have a string in which we have hat rat mat and part but I want to replace this rat I don't like rats all right so jokes apart I want to replace this rat and I want to replace it with the word food now let me show you how actually you can do that I'll again open My Pie charm let me first remove all of this I'll Define a string I'll name it as food although there won't be any food items in it but yeah just for the demonstration purpose hat rat mat and Pat now I want to replace rat with food so now I'm going to compile a regular expression into what are called pattern objects and pattern objects provides us with additional methods and one of which is substitute let me show you how you can do that just type in regx for example yeah regx equal to re do compile and I want to compile R which ends with at and now in the string food I want to substitute it so I'll type in regex do sub what I want to substitute I want to substitute food in which string I want to substitute I want to do that in the string food itself so yeah and now finally go on and print it so as you can see we have hat food mat and Pat so we have replaced rat with food so this is a pretty simple examples that I'm giving you right now but with these Basics you can actually go on and find find out a pattern and you can perform a lot of operations now there's one very important thing that I want to talk about it is called solving the backs slash problems now let me show you what I'm talking about so I have a string let me name it as a random string so I'll write it Rand s Str equal to here is drog bar all right so when I go on and print this let me show you what comes so we got only single backslash but we have typed in here double back slashes so this is what I'm talking about now in order to solve this problem what I can do is I can make use of regular Expressions so let me show you how you can do that so all you need to do is you need to type in r. search so this is re is basically we call it as raw string so raw string will treat backs slashes as special so let me show you how it'll do I'll just type in r. search then R quotation drogar comma and the name of the string that is random string go ahead and execute this so y it has solved our problem and you can see that double backs slash appears over here so this is what I'm talking about the backs slash problem all right so we have no doubts let me open my slides again and we'll have a look at the other operation that you can perform with random strings with that you can perform with regular Expressions now what I'm going to do is I'm going to match a single character so I have one 2 3 4 five is my string and now I want to print only the fifth digit so it should print five but before that we'll have a look at a couple more examples in which I'll be telling you about how to deal with white spaces so let me open my py charm again let me remove all of this yeah so now I'm going to Define one more string let me name it as random string equal to keep the blue flag flying high and ch see this is nothing but my favorite club and let me just print this random string so that's printed keep the blue flag flying high now let's go ahead and remove the new lines with a space so for that what I need to do is again I'm going to Define a variable let me lay it as regx equal to re. compile we have talked about compile in the previous example so I hope hope you can remember it so the symbol for new line that is a back sln then I'm going to type in the random string equal to regx substitute it with what what you want to substitute it with just a space right so just give a space in between that's pretty easy and just type in here random string now go ahead and print this random string yeah so as you can see earlier it like this keep the blue flag in one line Flying high in one line Chelsea in one line but with the help of regular expression I replace the new lines with a space so this is how you can work out with the white spaces so this is how you can work with white spaces now there are other white spaces that you'll be able to work with for example let me just show you so you have a back SLB that stands for what it stands for backspace then you have back slf for form feed then you have back SLR for carriage return similarly you have back SLT for tab and you have vertical tabs as well so for that we have back SLV vertical tab so so these are the white spaces that you can work with now let's see how to match a single character that we have discussed in our slides so let me first remove all of this all right so let me Define one more variable I'll name it as random string again and I'm going to type in here 1 2 3 4 5 and now what I'm going to type in I'm going to type in print matches I'm going to give a colon and then I'll type in length re. findall back SLT in random string now over here you can notice that we have back SLT so basically this back slash D will match any numbers any any numbers which are present but if I write a capital D over here so it will match anything but a number so let me keep it as back slash and print this and show you what it'll give us so we have five matches as you can see that we have five digits now if I make it as capital D so that will return me everything but the digits so let me just show you I've converted this to Capital D go on and execute this so we have zero matches now so now if I want to match a specific digit I'll be using curly braces so let me show you how you are going to do it so in the curly braces just type in five and it should print that for us so yep it has found one match that is present over here so I'll now what I'll do I'll clear this again and I'm going to Define in one more variable say Let It Be num over here I have one three then I have 1 2 3 4 then I have 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 five six and seven now we can even match digits with a certain range let's say our range is between 5 to 7 so for that what I'm going to type in I'm going to type in the print statement and again I keep it as matches give a comma and now I'm going to type in length re doind all what I'm searching for I'm searching for digits so back slash D and what is my range range is between 5 to 7 give a comma and then type in the string name that is num go ahead execute this and it finds three matches because over here we have five over here we have five and six over here we have five six and seven so it has found the three matches that we were talking about so this is how you can perform basic operations using regular Expressions now we have seen all basic operations that you can perform with regular Expressions now how about I show you what are the various applications of regular Expressions I'm going to take in some use cases approach problem statement and I'm going to show you how you can use regular expressions in order to solve those problems how about that guys all right so I see a lot of people are interested in that so without any further Ado let us move forward and see how you can do that all right so we have a first problem in which we need to verify the phone numbers so we have a list of phone numbers and the general format of a phone number is it should start with three digits then a hyphen sign then three middle digits and the three digits in between and a sign and then four digits in the end so this is what a basic format of a number is so let us go back to our pie charm and verify these numbers with the help of regular Expressions let me remove all this so before I start writing out the code let me explain you something so we have back slw so basically what it does is it is same as writing down lowercase A to Z uppercase A2 Z even numbers and underscore so lowercase w is actually equal to this thing that I have typed here so it will match anything that is inside the brackets when we talk about uppercase back slw it will match anything but the things inside the braces so it is similar to using a carrot inside the brace so I'll just show you so it'll match everything but the things that are present inside the braces so this is what I'm going to use in in order to write the code for validating phone numbers so let me just uh make a string that has my phone number so I'll just type in as phone and I'll put here 412 triple 5 and say 1 2 1 2 all right now I'm going to use a condition statement that says if. search so anything that has three digits then it should have a hyphen sign then again anything that has three digits then again a hyphen sign and anything that has four digits give a colon go on and print it is a phone number now basically instead of back slw I can even use as backt because all of these are digits but let me just keep it as back slw only and go on and print this so yep it is a phone number but what if I am going to change here and I'm going to make it as trip 51 let me show you it is not printing anything because so because our regular expression says that it'll take only three digits now as I've told you earlier as well W Takes A to Z lower case and uppercase as well so even if I replace it with d it won't matter let me show you go on execute this so y it has not printed anything but if I go on and remove this one and print it again so yep it has printed a phone number now if I would have added here a as well it won't print that so yeah so basically I wanted to tell you what back slw is that's why I have written it over here now let me tell you a use case of this black slw as well so if you want to see that a full name is a valid full name or not so what you can do is you can use back slw at that time so basically why I've explained you back slw is this is how you can use back slw all right I'll give you one more example so now let me remove all of this and now we'll see if the full name is valid or not basically there should be a space between first and last name so for that I'm going to use a back slash S which is same as writing down back slf that is form feed or a back sln that is a new line or a back SLR that is a carriage return or a back back SLT that is tab or vertical tabs so it is pretty much similar to that so it is exactly the same similarly if I write here an uppercase s can you guess what it will be all right so everybody almost guessed it so basically it'll be equal to a carrot and form feed new line back SLR tab as well as vertical tabs so it will include anything but back slf back sln back SLR back SLT and back SLV let me just common this all right so now let's go ahead and validate whether a valid full name is present or not so for that what I'm going to do is I'm going to type in a condition if. search now over here what I need to do is can you guys tell me all right so first I'm going to type in w and range of w should be between 2 to 20 then in between I want a space so I can just type in as now in between what I want I can have either a new line or a tab or a vertical tab anything like that so I can give a back SLS and one more back slw for the last name and the range of the last name can be from 2 to 20 and finally I'm going to write the name I'm going to write my own name give a colon and print full name is is valid go ahead and execute this so yep as you can see that it has printed the full name is valid so if I convert this lowercase s to an uppercase s it will basically be equal to a caret and form feed new line vertical tabs tabs so anything apart from all of these so I hope you have understood the concept that I've explained you till now all right so we have no doubt so now I'm going to move back to my present St again so now this was one use case now our Second Use case is we need to verify the email addresses so our email addresses should have 1 to 20 lowercase and uppercase letters numbers plus period underscore percentage plus minus it should have an adate symbol then again 2 to 20 lowercase and uppercase letters numbers plus period and hyphen then we should have one more period and then two to three lowercase and uppercase letters so let me go ahead and show you practically how you can do it let me remove all this and let me first write a list of emails so you can write it as SK atate aol.com I can have MD a.com adate SEO now I can have one more and I can name it as DC at.com let me just remove the space all right so now what I'll type in I'll type in print email matches give a call in and after the space I'm going to type in length re do find all open the parenthesis and over there in the Square braces what I want first I want anything then I want a period I want underscore percentage plus hyphen close the braces and it should range between say 1 to 20 after that what I want I want add theate after add theate I want anything for that I'll type back slw dot that is period Then I want a hyphen and what should be the range it should be between 2 to 20 characters after that I want a period and then I want uppercase and lowercase letters then it should range between two to three email all right guys go ahead and execute this so it has found only one map match so which is SK aol.com now if I actually copy paste this once more in the end and print this so yep we have two matches so this is how you can match the email address you just need to identify the format of it and you can do it all right so we have no doubts now let us move forward and see the third application of python regular Expressions so you can perform web scraping using regular Expressions now what is web scraping let me explain you with a flow diagram that is there in front of your screen so we have websites right and obviously these websites contains multiple web pages now if I want to scrape some useful information from those web pages I can use web scraping and extract that content and I can save it wherever I want I can save it in an XML format or a CSV basically however I want to save so you can do that with python regular Expressions so in our case what we are going to do there's a website and and that website we we have phone numbers we have uh addresses so what we are going to do we are going to write a code in order to get only the contact numbers from there and how are we going to do that we're going to do that with the help of a regular expression so for that I'm again going to open my py charm so guys I've already written the code so over here uh I've imported a couple of libraries in the beginning which are used to perform web scraping I mean they are used basically to read the web page uh then we have find all which we have discussed earlier as well now this is the URL that I'm talking about right so let me just uh copy this and I'm going to show you to you in my browser how it looks like so this is how our web page looks like so we have name here we have the address then finally we have the phone numers now notice a pattern in the phone number we have three digits inside the parenthesis then again we have three digits then we have a hyphen and then finally we have four digits just keep this pattern in mind and we are going to write a code in order to scrape only the phone numbers from this particular website let me close right now all right fine so now you've seen the URL right so apart from that whatever things that are there actually we have covered that in the web scraping tutorial so you pretty much aware about it so what is this we are basically reading the content that is there in our particular website now we'll focus on the regular expression part so you know what exactly find all is we have discussed that now since we want only digit so we are going to make use of this particular identifier and inside the curly braces I have written three which means that there will be three digits inside the parenthesis after that there's a space then again we have three digits then we have a highin and then finally we have four digits then save it in HTML St strr and then finally print it now let us go ahead and execute this and see what happens so we have scraped all the phone numbers that were there this is how it looks like and we made use of regular Expressions so you can use regular expressions for web scraping as well now that you understood regular Expressions we'll move on to the file handling you will learn how to read from and write to files in Python and feel free to drop your questions or doubts in the comments below our urea team is here to help you why we require file handling well guys think about this situation you have a server running and you need to give access to someone who needs to access it remotely right or basically you need to work with these files in general and say you need you need to have some import into your program where you're actually configuring an input for it well if I had to answer this personally how would I go about it I would be using files for a lot of my deep learning models to import my data sets into the program at all the time so basically by doing this I'll be making use of files a lot so coming back to the basics again how can we input something into python the standard input the usual keyboard input right so you can key in anything you want well there's another case as well maybe even command line arguments to input some parameters into the code correct but what if you had to read lots and lots of data which is not practical to type in at every point of time or even that it doesn't make sense at all to type it all the time the easiest way out of this here is to actually store whatever input you want in one place and keep using it as long as your requirement is met so what's the answer the answer is files guys so guys this concept is actually very easy I'm sure everyone who's joined will take away some really interesting stuff about python that you can practically use working with files basically opens another door among thousands and each door with python opens up to a number of opportunities again so now that we good with this and we started off on a really high role let's keep it going next we'll be taking a look at some of the types of files available in Python so guys let's keep the session very interactive head to the comment section and keep the energy going so can you quickly name all of the types of the files that you know so again let me help you here so we have images we have audio we have video we have text we have script and so much more right there is a key difference here I want you guys to note check this out windows supports all of these files that I told and more well virtually unlimited to be honest but again I won't get ahead of myself here because there are limitations here as well now check out python there are two types of files binary and text so whatever is not text is binary as simple is that so either a file gets to be a binary which contains obviously zeros and ones or it can have some literal text well text as in strings or anything valid for that matter text files are structured as a sequence of lines where each line includes a sequence of characters and this is what we call as code or syntax right and every line is terminated with a special character what we call as the EOL what is the EOL guys it's the end of line character a binary file is any type of file which is not a text file as I mentioned and because of their nature binary files can only be processed by an application that knows and understands the file system structure in other words they must be applications that can read and interpret binary right and now that we know what are the types of files are so we we can start looking into more of this guys formally speaking I think it can be Consolidated as the operations performed on a file right so what all can we do check this out it's called as the crud operations what is crud well create read update and delete Guys these are the operations which can be done with files well again there are many other operations as well such as copying a file changing the property properties of a file or anything but for Simplicity sake I have planned to keep this session really easy for all of the audience so let us dive into python now so let us quickly see how we can go about understanding the file handling capabilities of python check out this flow diagram to give you a quick picture of what needs to be done first we create a file and later we open that file we we work on the file well working on it is basically reading or writing or anything for that matter and lastly we close the file when we are done using it coming to python now creation of a file can be done manually by the user or through python for now let us consider that we will do it manually by going into the location and creating a file say like a text file later in this session I'll show you how easy it is to make python create the file for us so make sure you stay tuned till the end so now we concentrate on how we can open a file with python guys it is very simple so we have an inbuilt function called as the open function which is used for this exact purpose the open function takes in two parameters as seen here one is the file name and other is the mode and this on your screen is the Syntax for the open function so so what do the two parameters mean one is the file name that you want to open it can be anything at this point of time right so it has to contain the extension of the file type as well so this is compulsory and important so make sure you keep this in your mind and second we have the mode we know this means something that has to do with opening the file right so check the check the screen so basically these are various modes available to open a file we can open it in the read mode the write mode the append mode and even the create mode as well pretty straightforward but do not that that the default mode is always the read mode and guys note that you can open a file in read mode only if it exists as well if you try to read a file or something that doesn't exist then python will greet you with a beautiful error message and in addition if you want to specify if the file should be hand handled as a binary or a text mode then along with the mode as well we can actually push in two categories for it check this out so we have t for text and B for binary T is the default value and B is for binary modes so we can have something as WT so what does it mean so it basically says that the F needs to be opened in the right mode and the file that the python opening is a text file so we're basically making the job for python to to be really easy in this case so check out the example code I have here for you guys even if we do not give a mode as I said the default is the read mode so these two tiny Snippets I have for you are one and the same and yet make sure something exists before reading that guys or else you're sure to hit that error so check this out right so I have F equal to open and the file name is demo file. text I don't have a mode here this is exactly equal to having the read mode in the next example and it is as simple and straightforward as that so now we know how we can actually create a file and open it right so let's begin working on it let us start with creating on how we can actually do a read operation using python so the read operation is very easy guys so basically just like all the other functions and handling files in p we make use of the read function for this very purpose but then again there are so many ways to read a file too so let me so let me break it down for you all right so we can do many things here we can read an entire file or read a few characters or read a few lines or any number of characters and lines together and so on check out this example code here so we have a variable right we call it file and then we are opening the file it's it's called text file.txt and opening it in the read mode later we are actually going to make use of the print function to read the contents of the file and print the same on the python console now similar to the previous code that I just showed you we have something slightly different here can you notice that five on your screen what do you think the five indicates here guys let me help you out so basically tells the python interpreter to read the first five characters from the file and nothing else now check the old centx so here we don't have the five so we are basically telling The Interpreter to read every single valid character present in our file and print it out for us so you got a good picture of what is happening with the file now well let's quickly take a tour into seeing this practically so I'll open up my pyam now which I use as the ID to work with python where I'll show you the code for all of these guys you can basically make use of any IDs that you're comfortable with and even the console as well it is your call I am comfortable working with py Cham so I'll go ahead with that so let me quickly open up the ID and we can see the basic code to read the file so as you can check out I'm here in my pycharm right now importing the OS module is the first line This is currently being unused right now but I'm going to talk about this in the future session so basically we opening a file right so we have a variable file we're going to open it and we providing the entire path to the file present so here the file is demo file.txt this is the name of the file W is the right mode that I already told you about let me quickly go ahead and run this that ran fine but you cannot see anything on the output right that is because we just opened it over wrote everything that is present in the file and we just closed it so we not seeing absolutely anything here check out example two importing the OS module file equal to open again we providing the same file here we had right mode and now we having the read mode and here we are actually printing it using the file. read again I'll be walking you through file. read in a second but right now all you need to know is this will print the output on the screen for us if I go ahead and actually run it nothing is going to be printed why do you think this happened this happened because we actually use the right mode and we actually blanked out the entire file Quick Fix is to actually open the file as you can see nothing is present there so let me type in something so we love edure Rea let me save that quickly minimize it go back to my py charm now as soon as I run this it is supposed to give me that exact output which says we love edure Rea perfect right so with absolutely three to two lines of code you can actually print something on your screen how simple is this guys well check out the next case so again it's the same thing opening the file using the read mode and then you're printing file. read of Five Guys file. read of five right so I actually explained this to you so let me just go ahead and run it we'll check the output we got the first first five character right so w e a blank space l and O uh let us try to make it more nice to look at let me just quickly open up the file uh hello world this is a perfect candidate for our example uh yep the quick typo uh save it exit back into the code now I'm going to run this old code right so you're going to get the entire output here check it out hello world perfect because we have read of blank now we're going to actually run this because we're telling The Interpreter to read only the first five characters of the first line for us it is just printing hello how simple is this guys so now that we are actually done with this let's quickly jump back to the presentation to see what's next well guys next I want you guys to check out this syntax right so this is what I love about python amazing readability and you can almost guess what it means and you can be certain of it say 90% of the time so we saw how to read characters now let us look at how we can read lines well read line will actually read each of the lines and give us a line by line output read line of three will tell the python interpreter to read only the third line and absolutely nothing else but what if you wanted to return every line in a file which is properly set separated and nice to look at well you can actually use the same function only in a new form this is called as file. read lines function again let's take a quick jump back into the code so we can see this in action so check out example four on your screen I have the same file demo file. text I'm opening it in the read mode and I'm using read line soon as I go ahead and run this I will have the same output as hello world okay let us step it up a little let me just change this hello world we love Python and we love edura so I have three lines here all good right so I'm going to save it I'm going to close it I'm going to come back here and I'm going to run the read line again we reading only the first line cool check out example five now this is where things get interesting best thing inut again it's it's all the same guys so basically instead of the read line I have read lines over here so the S is extra and it's going to read all of these lines and it is going to put it in a really beautiful way for us to see check this out hello world is an entity we love python is an entity we'll have edu Rea as another entity and that's nice to look at right so instead of just get getting a gibberish output of everything in the line separating it actually makes a lot of sense so now that we're done with this another quick hop back to our presentation so guys next we need to check out a tiny concept on how we can actually Loop over a file object well this is another simple concept so let me teach you this we're using the for Loop for this very purpose as shown but why would we want to do this when you want to read or return all the lines from a file in a more memory efficient way and in a faster manner you need to use the loopover method so the advantage of using this method is that the related code is both really simple and easy to understand right so let me take another quick jump into pyam and check the single snip it out so we are back into py charm and check out this for Loop example I have for you so again we're sitting on the same file demo file. text reading it in the mode so for every line in our file object print read lines so is going to print the output for us containing all of the documents of our file as you can see we'll have Python and we love edure Rea that's really simple right and with this we are actually done understanding how to open the files and read them in multiple ways next we need to actually take a look at the right operation which is again very simple and almost similar to the read method let's start writing to a file is as simple as using the write function guys similar to the read again so to write to an existing file we make use of two modes one is the append and the other is write which we already checked out earlier by upend we actually add the contents of the right to a new existing content and with write we just add it to the blank file now I am sure there is a question in your mind right now so what if the file that I'm trying to work on is not blank what if it contains some previous data and we make use of w instead of append guys this will basically delete everything in the file and overwrite it with what you've just put and this is exactly the first example case that I actually showed you so make sure that you use the mode very wisely in every situation right so here's a quick example before we dive right back into code mode as you can see we open a file in the right mode and we write two lines into it and we close it it is as simple as that right now again taking you back to py Cham and let me walk you through the code so guys we back into pyam right now so check out the first example I have for you import OS I already explained opening it in the mode of right so since we already have some content all of that content will be overridden with hello world and hello world again so we're opening it we're using file. write to write two content into it and then we're going to close it let me run this again no output because we are not printing it to our console how do we check if everything is working open the demo file hello world and hello world again right so this is exactly what we wanted but then again this looks a bit gibberish as I told you right so we use read lines to make it look nice for us heading back to pycharm again check out the next example I have for you so now this is to prove that we actually overwriting it again which I've already told you and it is simple but still let me walk you through this so we're working on the same file we using the W mode and then we're writing it to it saying oops we have over written it run it it ran no output but in the sense the file is changed so it says oops overwritten instead of hello world and that old message that we put printed let me head back to the py cham again and this is for creation and we'll be coming back to this in just a second so let's quickly go back to our presentation and then we're going to be coming back to pyam again so we're down to the last two concepts that we will check out in this session the first one among that is for us to create a new file using python well guys even for the creation of the file we need to make use of the open method we already know that a is used for upend and W is used for right and now we have X which is used to create a file but do not that you cannot create two files of the same name guys so basically it means that you cannot create a file which already exists check out the example on your screen and you will definitely get a better picture of it right there so you cannot have two files with the same name test file. text this is not right so again python will give you a beautiful error message and it won't be so beautiful at the end of it let me dive back to pyam and we can check out the example over here uh let me change this we have something else right so let me type ua. text I'm going to print new file into edure Rea opening it we opening it in the X mode so we are actually creating this file physically write mode to write something into it and close it so it no output check out the file where is the file called edura it is here new file of edura so it's perfect right let me quickly head back to the presentation and we can check out what's next and then the next simple concept I have for you guys is showing you on how deletion operation works with respect to files using python guys deleting a file is very simple and straightforward we'll re the os. remove function just for this purpose so yes importing the OS module is a compulsion here I been using it all along because it is just a good programming Habit to use the OS module when you're playing around with the file system the biggest mistake I have seen people do is that they usually go on to delete a file which doesn't exist again python pushes in an error message and that is not good at the end of the day right so it is very vital to know for sure that the file exists to do this we just check if the path exists and if it does cool remove the file else print that the file doesn't exist so you cannot remove it what does this say guys this is a very simple case of an exception handled by the user and this is a really good programming habit too so all good but can we delete a folder yes we definitely can a folder with with all the content inside it can be deleted using the rmd command what does rmd stand for it basically stands for removing directory and the parameter here is basically the path and by the path it includes the name of the folder which needs to be removed and this is all of the operations you can do with python by making use of files with file handling covered we will dive into python database connections this topic will teach you how to connect to database and perform crude operations introduction to Python and my SQL well as you already know python is one of the most widely used programming language and in demand among developers but you can't merely develop any application without having to know where to store the data so this is where database management system comes into picture and one of the most widely used dbms server that is also used in the industry practices is my SQL DB server let me move ahead and talk a bit about integrated connection all right guys this is just a glimpse of how the bigger picture will look like what I'm trying to do is I'm basically trying to integrate my python with my backend database server and then do the further manipulations now let me move ahead and explain you the internal working logic behind when you establish a connection between Python and my SQL DB server or I can say that I'm basically going to explain you the internal working logic that how does it actually connect or work so as you can see there are numerous pictures given in this slide on my extreme right hand side there's a picture of a database and on my extreme left hand side there's a picture of a python application and in between lies the MySQL connector python API so my SQL connector python API is nothing but acts as a bridge between my frontend python application and my backend database server now when I see this word python application think of any python application let's say suppose think of a website which a user has developed which lies in the front end now my front end python application will basically send a connection request to the my will connect to python API then the API will forward the same request to the database further which the database will accept the request and send the connected message and then my python application will send a cursor connection request so over here think of connection as a method and cursor as an object which basically lets you communicate through your entire MySQL DB server and also lets you create your own database finally my python application will execute a certain SQL statement or a certain SQL query and for that my backend database server will fetch the result data so guys this was it with the internal working logic that basically Works behind when the python and MySQL DB server connection is taking place now let me move ahead and talk a bit about operations which I'm going to perform with python and my SQL so guys I'm basically going to perform crud operations which simply means create read update and delete with my Python and my SQL so let me move ahead and show you the implementation of crud operations from from coding point of view so let me quickly open my py Cham all right guys before diving deep into the coding perspective my first and foremost step is to basically import the MySQL connector package and how do I do that I'll click on file click on settings click on Project interpreter on the extreme right hand side there's a picture of a plus sign and then type here my SQL hyphen connector or right click on my SQL Hy connector click on install package it will basically take a minute or two to get installed essentially a first step is to install the my SQL hyphen connector package which forms the stepping stone for our further operations which I'm going to do again it is it'll take a minute or two to get installed all right so as you can see our package my SQL hyen connector has been installed successfully now one of the other approach to install the same thing is suppose this is for those set of users who don't use any python ID suppose you're using a python command line so for them quickly open command prompt once your command prompt is open quickly go there and type pip install MySQL hyphen connector which is the package and press enter well it is going to show me or give me a message that is requirement already satisfied since I've already imported the package on my py Cham ID but this demonstration I'm showing for those set of users who simply use Python command line so for them you can go to your command prompt type pip install my SQL hyen connector your my SQL hyen connector package will be installed and then you can import your same package on your python command line and then you can move on with the further operations so now it's saying me a warning this is none of our concern guys let me just quickly close it and as I've already created a file under the name name of python DB creation I'll move on with my coding demonstration so let me enter the presentation mode and start off by writing my first line of code so the first line of code which I'm going to write over here is I'm simply going to import the package which I installed just now that is my SQL hyphen connector I'm sorry it will be MySQL do connector now I'm going to create a local DB instance that is my DB under which I'm going to write my SQL dot connector do connect under which I'm going to pass in the three parameters that are host which is equal to your local host then comes the username that is equals to root and then comes the password which is equals to password 1 2 3 so root is the default username which I had given guys and password 1 2 3 can also be customized so this is the password which I gave now I'll merly print this local DB instance that is my DB quickly go ahead and run this code yeah all right yeah so as you can see the connection has taken place but how do I verify whether the connection has been established successfully or not so in order to do that I'm just going to write two more lines of code that is if my DB then print that is if it falls or if there's a local DB instance that is my DB then I'm going to print connection successful else I'm simply going to terminate this or I'm going to write print connection that is if there's a local DB instance that is my DB is coming or under my DB it is coming or the parameters are there then my connection will be successful else my connection will be unsuccessful let me move move ahead and run this code give me a minute guys well as you can see our connection is successful now I'll just change one parameter and see whether it's verifying that the connection will be established successfully or not now I'm going to change a parameter suppose I'm changing the root which is the default name of user to RAM and let's see if the connection is being established successfully or not or it is being verified or not well as you can see guys it's it says access denied for user Ram as because our default username was root which I had given so it will not be getting connected to our MySQL DB server now let me quickly write back root over here and move on by creating a database so in order to do that I'll quickly open file I'll create a new python file with the name as python DB creation let me just name it python DB1 creation Now I'm going to write my first line of code that is importing my SQL do connector which is the package then I'm going to write my DB is equals to mySQL do connector do connect under which I'm going to pass in the three parameters that are host which is equals to your local host then comes your username that is equals to root and then comes my password that is equals to password 1 2 three finally I'll move on and I'm going to show you what I'm going to do over here so I'm going to create an object the name as my cursor under which I'm going to pass my db. cursor which is pointing towards the location and finally I'm merely going to print this object that is my cursor. execute under which I'm going to write create database and let me say my database name is H DB all right and then I'll quickly move ahead and run this code let's see what is the output all right so it says that the database has been created that is H DB has been created now I'm going to show you whether this database is existing in our MySQL workbench or not so in order to do that I'll just change few parameters and add a for Loop I'll explain you about the for Loop part later so let me just omit this part hdb and instead of create I'll simply write show over here and then over here I'm going to write show databases now I'm going to write for DB in my cursor I'll simply print the database all right move on and run python DB1 creation file well guys as you can see from the output the reason why I used a for Loop over there is because once my code enters the for Loop it is basically printing all the databases which are existing in our MySQL workbench along with the database hdb that we have just created which is there in our output so it's very clear now I'll quickly open my MySQL workbench and I'll write the same SQL query over there so that it's crystal clear to you all right let me quickly maximize it one second now let me simply write show databases and click on execute 1 minute guys well as you can see our database hdb has been created along with all the other databases which are existing in our MySQL workbench now let me just refresh the schemas all right so let me just minimize this and I'll move ahead by creating a table under the database so I think you guys are pretty clear with the concepts which I explained just now I basically started off by creating or by establishing a connection between a Python and my SQL DB server further I moved on and created a database and now I'm moving on and creating a table under the database hsh DB now how do I do that well let me create a new file first one second I'll name it as Create TV and python all right all right guys before moving ahead I'm going to tell you one thing the first three or four lines of code are going to be same everywhere I don't find it useful by repeating the same first three lines of code everywhere again and again I don't want to bore you with the same thing so let me just copy paste it into the presentation mode yeah contrl V now I'm going to write my cursor. execute it's going to be create table suppose I give my table's name as employee under which let me pass two parameters there'll be name varar 200 salary integer 20 we just close it move on execute this code well I have done a very silly mistake guys and the error is also very self-explanatory it says no database selected I'm going to pass a parameter over here it's going to be database is equals to hsh DB and let me quickly move ahead and run this code one second yeah all right so when I run this codee our table has been created now I'm going to show you the table which I have just created in our database H DV so I'm going to write the same code what I wrote while I was showing you the database so let me just omit these things and add an S over here and instead of create let me just add a show and let me type A for Loop so it'll be for TV in my cursor print your table all right now let me move ahead and run this code so as you can see we have created only one table under the database hdb so it is showing that table which is employee now I'll show you the table in our MySQL workbench so one minute guys so instead of databases let me just write tables let me just select the hdb thing over here instead of databases let me just write tables select her TV and then execute this yeah so once I execute this well as you can see it is fetching the table and our table employee has been created on the extreme left hand side under the schemas column now I'll quickly minimize this and I'll move ahead by doing the read operation so before I dive deep into the read operation guys let me give you a small introduction about this so our read operation will basically happen in two stages in my first stage I'm going to populate my table with some values and in my second stage stage which will be the main stage where I'm going to do the read operation consisting of two fetch functions so I'm going to talk about the fetch functions later first let me just in order to populate my table I'm going to make use of insert command from the SQL query so let me just name it as insert op table and move ahead yeah control V before there's one more parameter which I left it's going to be database is equals to hsh DB now moving on let me create a new variable with the name as SQL form and under SQL form I'm going to write the SQL query insert into employee one second guys pass in the two parameters which I declared which were name and salary values and make use of or I'm going to write percentage comma percentage well guys these percent s are nothing but placeholders you can replace them anytime you want with any other value now I'm going to create a tle now the reason why I'm creating a tupple is because again in my second stage where I'm doing the read operations I'm going to make use of two fetch functions so there's one fetch function called fetchall so when I'm making use of fetch all I need not populate my table with a single value because that will not look good that's the reason why I'm creating a tupple over here so that to give you more clarity into what happens now let me just name it as herid let me give my salary as 20,000 comma Amit salary as 30,000 comma an and her salary is 40,000 comma space yep I think I need to put this back yeah now when I move on I'm going to Simply write my my cursor dot execute many because if I use execute it is just going to execute a single value but since I'm making use of a tle over here I need to write my cursor. execute menu and call in SQL form comma employees and finally I'm going to write my DB do commit which is going to save my changes from my last executed SQL statement now let me quickly move ahead and run this code so as you can see our insert operation has taken place and our tle has been inserted into the table employee under the database hsh DP now I'll quickly exit the presentation mode and show you the same in our MySQL workbench it's going to be the same thing I'm going to write select star from employee and click on employee on execute one second guys yeah I'll click on the result grid over here well guys as you can see this select star from hd. employe well it changes nothing Our concern is to basically view the topple which we have created and that topple is being viewed in the result grid that is under name and salary the values which we passed that are harid Amit anida with the salary as 20 30 and 40,000 let me quickly minimize this and moving ahead I'll be creating a new file and let me just name this file as ROP table all right now enter the presentation mode once again copy the first three lines of code over here what I'm going to do is yeah let me pass the parameter database which is equals to hsh DB and then I'm going to start off my read operation by the first function that is fetch one so let me write my code and then side by side I'm going to explain you also why am I writing that part so I'm going to Simply write my cursor. execute let's say I'm going to write a SQL query that is Select name column from employee okay this is a very simple SQL query and let me create a new variable and let me name it as my result under my result I'm going to write my cursor. fetch one now guys this is one of the most important part of my code because this is the first fun fun of read operation what fetch one is going to do is it is going to fetch me one value from the column name under the employee table all right now when I move on let me write the for Loop that is for Row in my result print the row and when I run this code as you can see it has fetched the value hit from the row name under the table employee which is again under the database htb as you can see this code is pretty self-explanatory when I make use of the fetch one function it basically fetches a single value from the column name under the table employee now let me just quickly move on with my next function of fetch in order to do that let me just make few changes in this code so instead of name suppose I'm going to fetch the whole tupple it's going to be select start from employee and instead of fetch one let me write here fetch all and let me run the for Loop so it will be for Row in my result print row all right now when I run this code I'll explain you why am I doing it or what does fetch all do well as you can see from the output the whole tle has been fetched now when I make use of the fetchall function guides it basically fetches the whole tle for us as because we writing the SQL query select star from employee so all the values which are there under employe table which was in the form of a tupple when we inserted it a while ago while we were writing the insert code that whole tupple gets fetched now I'll exit the presentation mode I'll go to the MySQL workbench and run this code once again well as you can see there are no differences the name is still there with the values Harang and salary 20,000 30,000 and 40,000 suppose I write this thing select name from employee one second I'm going to show you the changes of the fetch one functions in order to do that let me just write name again over here name and instead of fetch all let me write fetch one all right let me quickly go ahead and run this code so as you can see it is fetching here now I'll go to the MySQL workbench and click on same thing well guys uh these changes are not taking place over here because uh we were showing you the changes in the pie charm and since we applied a for Loop over there that's the reason why it is doing it but since when we are using the backend database server we need not do that because we are not using any Loop or we are not doing anything we are simply fetching the name whole column from the table employee now I move on and uh do the update operation so in order to do that let me just create a new file a new python file and name this as update pop table yeah let me close this just click on this enter presentation mode yeah control V let me pass the parameter which was database that is equals to H DB moving on let me create a new variable with the name as SQL under which I'm going to write update employee Set uh 1 second salary let me set the salary to 70,000 making use of the wear Clause where name is equals to let's say I'm updating Ang's salary to 70,000 and finally I'm going to write my cursor dot 1 second execute call in the SQL thing and then write my DB do comment quickly go ahead and run this code our update operation has taken place and in order to see the changes let me quickly go back to the read operation I'll show you the changes in both places in the py charm and my SQL workbench to so the last code which I wrote let me remove this and right here select start from employee this was fetch all okay Enter the presentation mode once again yeah run this code as you can see from the output the changes have taken place and Anita salary is updated to 70,000 which was 40,000 before I'll quickly move on and show the same changes in the MySQL workbench which is quite easy let me just run this code uh this should be star over here yep and then execute it as you can see an's salary over here is again updated to 70,000 now I'll move on and do the last operation that is delete operation which will also conclude my tutorial it's going to be delete op let me name it as table all right enter the presentation mode once again copy the first three lines of code I'll pass here the database parameter database is equals to H DB I'll move on and let me make use of the same variable which we used that time say suppose delete from employee where name is equals to suppose I'm deleting my record guys which is hit and then my cursor do execute all in SQL and then write my db. commit which is going to save the changes from my last executed SQL statement let me quickly go ahead and run this code well the database spelling which I use is wrong I guess well as you can see from the error it's quite Justified it says unsupported argument datab B so the datab spelling is wrong let me quickly Rectify that one second guys yeah I'm going to write a over here I missed it my bad and run this code once again so as you can see our delete operation has taken place and I'm going to show you the changes exit this we'll go to read off I'll enter the presentation mode once again run this code well as you can see the record her has been deleted from here and the same thing would be or the same changes would have taken place in the MySQL workbench let me quickly open it and run this code once again well as you can see the record how is deleted from here to after learning about database connections let's explore web development Frameworks you will discover the Frameworks available for building web applications in Python what are Frameworks in python python is a general purpose programming language it is one of the most popular programming language nowadays we can use it for so many applications including web development now a framework is a collection of modules or packages which helps in writing web applications or it helps in web development now we don't have to worry about the lowlevel details such as protocol sockets or thread management when we are working with a framework Frameworks make the developers life easier by giving them a structure for app development they automate the implementation of common Solutions which gives the flexibility to the developer to focus only on the application logic instead of the routine processes they provide common patterns for faster reliable scalable and easily maintainable web applications now let's take a look at a few operations that I use to run web applications using Frameworks so I have listed down all the operations here so first of all we will talk about URL routing so URL routing is the mechanism of mapping the URL directly to the code that creates the web page the next one is the input form handling and validation coming on to the next operation is output formats with templating engine now you must be wondering what a templating engine is a template engine allow developers to generate a desired content types for example HTML XML or Json we also have the data connection configuration and persistent data manipulation through an or or is also known as object relational mapper now you must be wondering what is the function of an orm an object relational mapper or an orm is a code library that automates the transfer of data stored in a relational database table into the objects that are most commonly used in an application code we also have the web security against cross sites request for also known as csrf SQL injection cross-side scripting and other common malicious attacks as well the last but not least is the session storage and retrieval so these are only a few operations we can perform using the Frameworks in Python now let's try to look at a few advantages of python Frameworks first of all python Frameworks are open source which means you don't have to spend any money while working on a python framework the next one is it has a very good documentation all the Frameworks in Python have have a very good documentation which means you can learn easily the functionalities and the key features of any framework using the good documentation that it has the next one is the security where it provides security against the malicious attacks and then there is integration and efficiency as well so these are the advantages of using a python framework for web development also there are a few limitations when we are working on a python framework which is it is open source so the code is going to be public so that is one issue here also there are a few limitations when we are using a framework because the difference between a library and a framework is it adds to a few rules and regulations when it comes to a framework now let's try to understand why we are using a framework now we know that Frameworks make it easier to reuse the code for common HTTP operations and to structure projects so other developers with the knowledge of the framework can easily build and quickly maintain the application so these are the advantages which is why we are using a python framework that is easier implementation we have the maintenance and the readability is pretty good and then there is code reusability as well so these are the reasons why we are using python framework instead of a library right so now that we have understood what are Frameworks and why we are using them in Python and also we have discussed the key features and advantages of python Frameworks now let's try to look at the top five Frameworks that we have in Python so first of all let me talk about D Jango guys Jango is a free open-source and a full stack python framework which includes all the necessary features by default it follows the dry principle which says don't repeat yourselves also Jango uses or to map objects to the database tables some of the exemplary features of Jango are authentication URL routing template engine and the orm also there is database schema migrations as well now the main databases that Jango works with are postgre SQL MySQL SQL light and Oracle also it follows the MVC mvt architecture so let's try to understand what is an MVC mvt architecture the model view template or mvt is slightly different from MVC which is the model view controller in fact the main difference between the two is that D Jango takes care of the controller part itself the controller part is basically the software code that controls the interactions between the model and the view leaving us with the template now the template is a HTML file mixed with the Django template language now looking at the diagram we can understand that the developer provides the model The View and the template and then just Maps it to a URL and Jango does the magic to serve it to the user so this is the MVC mvt architecture guys and this is all about D Jango now let's try to understand the next framework that we have which is actually web 2pi web 2i is a scalable open source and a full stack python framework however you should know that it does not support Python 3 now what is so great about web tupi right it comes with its own web paced IDE and among other things includes a separate code editor a debugger and oneclick deployment as well now looking at the other valuable web TPI features it includes no requirement for installation and configuration it has the ability to run on different platforms it has the ability to read multiple protocols it also provides us with data security that prevents such vulnerabilities like crossr scripting injection flaws and ious file execution it also has a error tracking system through error logging and ticketing systems also it has the ability for role-based access control and last but not the least it has a backward compatibility that ensures user oriented advancement without the need to lose the ties with earlier versions so this is all about web2py Guys these are all the features that we have in web2py framework now let's talk about the next framework that we have which is flask framework so talking about flask flask is a micro framework guys now the difference between the full stack framework and a micro framework is the full stack framework does the heavy lifting for the application that we are making but the micro framework is small and very easy to use also when we are using the micro framework the URL routing is going to be restful for many of the occasions so this is the basic difference between a full stack and a micro framework guys now let's try to look at the features of the flas framework so I've already told you it is a microne framework it is lightweight and it has a modular design which makes it easily adaptable to developers needs it also includes a number of useful outof thee boox features which include a built-in development server and a fast debugger it also has an integrated support for unit testing and the restful request dispatching one more thing guys FL support the Ginger 2 templating now you must be wondering what is a Ginger 2 templating right so Ginger 2 templating is nothing but a modern-day templating language made after the Django template language coming on to the next features we have a flask it has secure cookie support that is the client side sessions then we have wsgi compliance as well which is the web server Gateway interface now you must be wondering what is wsgi guys it actually implements the web server side of the wsgi interface for running the python applications that we are making now flask is also uni code based and also has the ability to plug in any urm last but not the least we have the HTTP request handling as as well so these are all the key features of flask framework guys now that we are done with flask now let's move on to the next framework that we have which is bottle talking about bottle bottle is also a micro framework guys originally it was meant for building apis bottle implements everything in a single source file it has no dependencies apart from the python standard library now its default features include routing templating utilities and a basic abstraction over the wsgi standard bottle is a perfect solution for prototyping learning the organization of web Frameworks and building simple personal apps so these are the features of bottle framework which is also a micro framework guys just like flask so now that we are done with the key features of Bal let's take a look at the next framework that we have which is cherryi cherryi is an open-source minimalist web framework it makes building python web applications no different than building any other objectoriented program program it allows you to use any type of technology for templating data access and so on however it still able to handle sessions Statics cookies file uploads and everything else that a web framework typically can now let's try to take a look at some default features of cherryi it has an HTTP compliant WGI thread pooled web server it has the Simplicity of running multiple HTTP servers at once it also has a powerful configuration system a flexible plug-in system it also has outof the box tools for caching encoding sessions authentication static content Etc now cherryi also has a built-in support for profiling coverage and testing and last but not the least it also has the ability to run on different platforms so this is all about cherryi guys now that we are done with the top five Frameworks and we have discussed the key features of all these Frameworks let me take you to pyom guys where I have a sample project that I have made on Jango and flas so this is actually where my project is saved guys so I'll go to my project and this manage.py file is actually the file which helps with the management of the site and we can start a web server without installing anything else so I'll copy this path guys and I'll go to the project that I have made over here and if you want to know how you can make a project or install Jango on your system and then make a web app you can simply go to the Eda YouTube channel where we have the detailed tutorial about Jang in which we have a detailed tutorial about Jango web development and where you can actually learn to build a simple app from scratch so what I'll do is I'll just write the path that I have copied so now that I'm in my directory where I want to run my server I'll just write python do manage.py to run my server I'll just write run server now you have to pay a little attention to these files that you get while creating your project in Jango so these files are there so settings.py file actually has the configuration of your website and url.py have the list of patterns that will be used by the URL solver and then you have the database the time zones and everything else that you can actually edit in your settings.py file so I'm not going to go line by line explaining everything so I'll just explain you that I have one more directory PS over here which is actually my app and in this I have migration and the template inside the template I have the HTML file where I have actually written the code of my survey form that I have made that I will show you guys so when I run this server what is going to happen is I'll get address wait let it run so I'm getting this address guys so when I go on this address and write poll that is the name of my app I will get this survey form that I have made and stored inside the template that I had made so this is actually a very basic survey form that you can make from using the D Jango app so let me show you guys what the same thing you can do using flask so I have also made a project using flask as well so in this we have the main file main.py when you install flask you can simply import it and there is no I'll show you guys in the project interpreter so inside project interpreter you can just add flask over here if you don't have installed it in your system you will find it over here you can install the package and you are good to go so now that I have told you about the main.py then we have a render template in which we are going to store the HTML file the template that we have inside this I have also written the same code for the survey form and to run this server we are just going to run this main file and you will get an address see over here and when you go over here and type the name of your app that is profile you'll get the same survey from that I had got so this is a sample project guys that you can make for practice although it is a very basic thing that you can do you can connect it to your database and there are so many things that you can do while using these projects so this is only a very basic project that I have done using this with an understanding of web development Frameworks we will move on to the python web development you will learn how to create Dynamic web applications using python why python is used for web development guys python allows you to build web applications dynamically it's a very stable language it also grants you ease to build multi-protocol Network applications the fact of python being flexible easy to use and its quick processing are just a few reasons to mention for its worth in web development now that I've explained about the features of python let's take a walk through some of the libraries that python provides for web development guys python provides a number of libraries for web development some of the important ones are cherry pie Jango web tpie pyramid turbo gares and flask among these in today's session I'll be using the D Jango framework so now youall might be wondering why Jango and why not any other Library D Jango is truly the best python library for web development it's written purely in Python and it's fast you can create websites within a matter of few hours it's fully loaded with all the required tools to create websites and it's very secure be it YouTube your Dropbox Google or Instagram all these internet Giants rely on Jango so with this I think I've given you enough for why I've chosen D Jango over the other libraries so as you can see over here web project has been created within the current directory so after this I'll just open up the terminal and over here I'll use the command pip install Django it's going to take a while to install Django guys so when you're installing D Jango along with Django the SQL pars database and the pytz module also gets installed SQL pars is actually a non-v validating SQL parser for python it provides support for parsing splitting and formatting SQL statements now this is actually compatible with the versions of python from 2.7 the pytz module is actually a third-party module that brings the allsen TZ database into python TZ actually stands for time zone guys this Library allows accurate and crossplatform time zone calculations using python 2.4 or higher it also solves the issue of ambiguous times okay so once Dango has been installed it will throw a message saying successfully installed Jango with its version and the version of the pytz module and the SQL parts now to cross check the installation of D Jango go to your command prompt and use the command python hyphen M Jango hyphen hyphen version now when you use this command it should return the version of Jango that's been installed so I hope everyone's getting the same okay so now let's close this I hope everyone's clear with this for any doubts guys please do let me know in the chat box because my team is always here to help you so now to create ajango project within this project I'll use the command Jango hyphen admin start project and I'll give a name to my project let me give the name as demo project okay so now a demo project has been created within the web project directory let me open this directory and here it shows the web project that's been created let me just go to the presentation mode and show youall I'll go to view and I'll select the files that I want and the terminal as you can see over here within the demo project directory there's another directory with the same name as my project and there is a file created by Jango called as the manage.py file the manage.py file is actually a command line utility that lets you interact with the Dango project don't worry guys we'll be using this many a times so you'll get familiar with this now let me just open this directory and see what's present within it the first file that's created within this directory is the init.py now the init.py is actually an empty directory which is considered to be a package after that there is something called as the settings.py this actually consists of all the settings that are necess necessary for the current project after that it's urls.py urls.py consists of all the URL declarations for this project and finally the wsgi.py file where wsgi stands for web server Gateway interface now this is actually a calling convention guys for web servers to forward requests to web applications or other servers so I hope everyone's clear until here if you have any doubts do let me know in the chat box okay so now to check if I'm able to connect from my project to the web server I'll just get into my project using the CD command and after this I'll use Python manage.py run server like I told you the manage.py file will help me connect to the server so this will return an IP address so when you click on that address you will see a screen with a rocket which is ready to take off so congratulations guys your rocket is ready to move on which means you're all set to create your own websites so I know that after this everyone would be excited to create their own websites to do so I'll just get back to my pycharm and show you guys what exactly you must do to create your own websites okay so to create my website all I'm going to do is create an app within my demo project I'll just return the control to my terminal using control C and over here I'll create a new app within my project please make a note guys that one project can have n number of apps which means you can include any number of apps within your project to create an app I'll use the same command which is Python manage.py and instead of run server I'll use the start app command and I'll give a name to my app let me just give the name as demo app so now an app has been created within my project let me just open this up to show you all what's present within this demo app so just like how Jango had created files for us within our project when we created a new app Jango has created the necessary files for us so this is what D Jango does it writes all the necessary code and all you have to do is write your website specific codes and just modify the files that are present and add your own files as per your choice the first file that I'm going to open over here is views.py and as you can see over here Jango has already imported render for me now I want to use the HTTP response function so I'll use from Django HTTP import HTTP response please be careful with your spellings guys now within this file I'll create a new function using the de F keyword and I'll give the name of the function as high to this function I'll pass one parameter which is request within this function I'll just write one return statement using the HTTP response function I actually want this function to return a message saying that this is the homepage of my website I'll just put it as a string and I'll use the H1 tag for this this is my homepage and I'll close the H1 tag slh1 so as you can see over here P charm has highlighted this line because I'm using the HTTP response function the first line of my code is not highlighted because I'm not using the render function anywhere as of now I'll not be using the render function however I'll be showing youall how to use this later on okay now I've created views for my project but I will not be able to connect this file to the urls.py which is present in the demo app to connect views.py to this urls.py I'll have to create another urls.py within the demo app directory and connect that urls.py to the urls.py which is present in the demo project don't get confused guys I'll be doing it over here and the video will be available after this in case you have any doubts you can go through it again so I'll just create a new file within this app it's going to be a python file I'll give the name as urls.py and I'll say okay this urls.py is actually very similar to the urls.py which is present in the demo project so I'll open the urls.py present in the demo project directory and I'll copy the from statement which is from Django do urls import path and the URL pattern list I'll just copy this and I'll go to urls.py present in my app and I'll paste it over here now over here since I want to map the views.py into this urls.py what I'm going to do is use from dot which means from the current directory import views and within the URLs pattern I do not want this admin path so I'll just remove this and I'll leave the name as blank because I want this to be mapped to my homepage and over here I'll use views. high which is the name of my function and I'll give a name to this path you can give any name of your choice let me just give the name as homepage home hyphen page okay so after this what I have to do is map this urls.py to the urls.py which is present in the demo app so I'll open the URL py present in the demo app and over here I'll Create A New Path and I'll give an empty string because I want it to be mapped to my homepage like I already told yall uh oh sorry guys I'll have to import the include function also so from Django do URLs I'll import the include function and over here I'm going to use the include function I'll map the urls.py present in my demo app and I'll close this so after this let me just go to my terminal and use Python manage.py run server I've just made a name mistake this is demo app okay so as you can see over here it has returned the IP address again I'll click on this IP address congratulations guys instead of that rocket which we were seeing previously which was the default page my website is displaying whatever I want it to display so this was the message I wanted to display on my homepage and it shows that this is my homepage so now I'll get back to my pycharm and I'll see how I can modify this page to create a website I'll return the control back to my terminal using control C so to write HTML code within this project all you have to do is create a new directory within your app directory and that will be the templates directory now these will be the templates that are specific to this project and instead of looking elsewhere D Jango will look into this directory for the necessary templates within the templates directory I'll create a new directory with the same name as my app don't get confused with this guys this is actually the Jango convention which helps you write Project Specific code So within this demo app I I want to write the HTML code so I'll create a new HTML file to write all the HTML code that I want I'll just give the name as high. HTML and I'll say okay so as you can see over here D Jango has already written the minimum HTML code for me I'll just change the title to edureka guys you can give any title of your choice and within the body I'll just write Hi and after this I'll open the apps. py file I'll copy the name of this class and then go to settings.py present in My Demo project and over here I look for installed apps remember that whenever you create new apps you'll have to add it over here then within a string give the name of the app which is demo app please be very careful with the spellings because if you make any mistakes it's going to throw a lot of errors and you'll not be able to understand why it's throwing such errors and and for beginners it sometimes gets very confusing to debug these errors so just be careful over there so let me get back to this name of my app which is demo app do apps dot the name of the class that we've copied from there I'll just paste it over here and I'll specify a comma after this now from here I'll go back to my views.py file and instead of this HTTP response I'll be using the render function so I'll just remove this I'll return render and I'll specify the request function and then within a string I'll specify the HTML file which is present in the demo app so demo app SL high. HTML which is the name of my file guys please write the same name which you have given to your file I'll run my server again after this so python manage.py run server let's go back to our server and see what happens so as you can see over here guys the title has changed from the default address to edureka and my homepage now shows a message saying hi so I hope everyone's clear with everything until now now all I'm going to do is go back to my HTML file and do some modifications to create my own website so now to create my own website I'm just going to modify this HTML page guys if you're done till here you've been successful in creating a website now all you have to do after this is specify your Project Specific HTML code let me just show you a few basic things that you can do using HTML over here so I hope everyone knows some basics of HTML let me just change the message from hi to welcome to edureka okay I'll just specify the second line of my page to be some h2 tag and a new message saying that this is my website let me save this and rerun my server I'll just go back to my server and I'll reload the page so as you can see over here the H1 tag says welcome to edura and the second h2 tag says this is my website so this is how you can write your own HTML code to your program guys so now let me create some list over here to create list I can either specify it to be an ordered list or an unordered list for ordered list I'll have to use o tag and for unordered list I'll have to use the UL tag over here I'll be using the unordered list and within this list I'll specify the list elements first element is Python and the second element I'll give us Java or something okay let me save this go back to my server and reload this page so as you can see over here guys it has created an unordered list over here so now let me show youall how to create a table over here so to create a table for your website you can use the table tag and specify whatever style you want for your table in my case I'll just give the width to be 30% and I'll close this so within the table you can have the TR the th and the T T tags the TR tag is actually for the table rows th is for table headings and TD is for the table columns I'll just write a TR tag over here and within this TR tag I'll specify the th tags let me just give the heading as Python and I'll give another heading as Java so after this I'll create another row using the TR tag and within this I'll specify the columns so for that I'll use the TD tag and I'll just specify which IDE you can use for Python and Java so for python you can use pycharm let me just copy this and for Java you can use Eclipse so I'll change the name from pycharm to Eclipse over here and I'll save this so as you can see over here a table table has been created but guys my table over here does not have any borders to add borders to my table I'll go back to my HTML page and over here within head I'm going to use the style tag and within this tag I'll specify what border I want for my table let me save this and reload my page so as you can see over here guys I included the style tag and specified what kind of Border I want so the same way on my server over here a table has been created with a specified style to know more about HTML and learn how to create beautiful websites you can just go to the bootstrap website and from here you can take any code that you want for your website so I'll just show you what happens when you use this so let me just use the style from the bootstrap and it should be present within the head so I'll just paste it over here let me save this I'll go back to my server and I'll reload this page as you can see over here guys using the small bit of code that was present on the bootstrap website my website looks so much more better than what it was looking before this you can use this bootstrap website to create your own beautiful website now that you know how to develop web applications let's talk about web scrapping you will learn how to extract data from website using python now let me begin with the very first topic that is the need of scraping or why do people actually scrape a website so scraping is basically extracting data from various websites now there are many ways to collect data online but let's say I just want to collect data for comparison so here let me take an example of my smart price which is known for best price comparison so what they do they collect data directly from Merchants now the larger stores generally provide the feeds which are listed on their stores but what about the smaller stores now one way of doing it is to either copy the prices from different websites and then paste it to your local system which will in turn be a very tedious job and it will consume a lot of time as well so what you can do you can simply scrape the prices from different websites now apart from these there are many use cases or you can say real life examples where people do scraping so here first is your e-commerce portals now here what you can do you can build your own website and then scrape products from retailer or you can say manufacturing websites so basically you can scrape prices ratings images or any other specifications as well then you have market research so here scraping can help you in providing important information to identify to analyze the market to analyze the need its size and the competition of Market as well now it can be any kind of industry it can be your travel areas where you can scrape reviews or you can scrape products or any places hotels restaurant or it can be anything then you have social media so here people scrap business profiles from social networks and track their online presence and reputation and hence the list goes on so people generally use web scraping to build the best marketing strategy monitor them and hence upgrade their business so in a way web scraping provides them a way to get information whether it can be a website prices it can be images it can be data for any for any analyzing purpose as well so also you do scraping because many websites do not provide an API unlike Facebook Twitter and all but in many cases you will find that web scraping is the only alternative to get data out of them so we have discussed the various real life use cases which uses web scraping but here the question is is it actually legal well maybe scraping is fine till you are not causing any considerable damage to the Target website and you are doing it responsibly so website is legal as long as there is no attempt to change the article or blog or anything you should not try to override the restricted access of the website or play around with the security mechanism now let me tell you the companies who have faced problems while web scraping so you all must have heard about LinkedIn so in 2014 there was a case where the Su a group of dependents in California now this case was based on Digital Millennium Copyright Act where they used a series of bards and fake profiles to scrape the data from other member profiles so that is why you should always know the difference and respect the fine line between collecting information versus stealing it so now let's understand what exactly is web scraping now as I've already explained you the need it will be very easy for you to understand this concept so web scraping is a method where you pull data from different web pages extract the useful information and then store the same data to your local storage now this local storage can be in any form it can be in XML form it can be CSV or it can be any database as well so web scraping is a technique where you automate the procedure within a fraction of seconds instead of manually copying the data from websites now we know scraping is when you extract any information now if you want to extract through a browser or a website or web page so that process is known as a web scraping so let us see the basic steps which are involved while scraping so the very first step is document load now in in our case we are doing web scraping so we have to load the entire document which is your HTML page next is your parsing so parsing is basically basically where you interpret your document to make your searching possible so in HTML there is a Dom by which you interpret all the HTML code next is your extraction so here you simply extract anything like the name like the price or any specification of the product and the last is your transformation so here it basically converts the data into useful formats like for example you can change the type here now if you have a date string and you want to Output as date so you can transform it in any form so these are the steps which are involved to do simple scraping now let us see what are the different packages that I use for web scraping although I would recommend python because a lot of people use it for web scraping well the good part about python is that it has libraries for everything now this is why it is the goto language for many developers now as you can see here there are a lot of libraries which are used for web scraping such as pattern Scrapy mechanize beautiful soup and request so I have only used scraping I have also I've only used python for scraping because what I like about python is that it makes a string manipulation very easy so string manipulation basically is the key where you pass any information from a page along with this it is also compatible with various databases such as your nosql databases like mongodb and mongodb is what we mostly prefer effort to use for data storage in web scraping now as you can see there are different python packages now these are not enough we also have some other python libraries such as xath you have PDF you have minor and many more but here if you see beautiful soup and request are the most popular libraries in this lot and later in the demo we'll be implementing them as well so beautiful soup is a python Library which is used for pulling data out of your HTML and XML files now it provides you simple in fact very simple ways of navigating searching and modifying the HTML and many more things like that next is your request so request is a library which is widely used for sending and receiving information over HTTP well that's all for the theory part so now let me move on to a demo part where I'll be scraping a website from the scratch excuse me so here we'll be scraping flip cart now let's see what all we can scrape from it so we all know flip cart is an e-commerce company so what I'll do first I'll so what I'll do first I'll simply search a product on flip cart let's say an iPhone so here as you can see the list of all the iPhones will be displayed now what I do I have to fetch the name of the iPhone what are the configurations what are the ratings and what is the price of the iPhone so fetching all these details is I need to First view the HTML page now how will I do it I have to Simply right click it and go to the inspect so this will basically open up my HTML code now this is my HTML code so to understand this HTML let me open my py charm and let's understand each component one by one so this is my Pyon Community guys and as you can see this is the code for scraping flip cart well it is not that big code because python makes it very easy it has a very it has small syntaxes and it is very much similar to your English language as well so what I have done in the beginning I have simply imported two libraries which are beautiful soup and request so these libraries I've already discussed so how you can import them you can simply go to file then go to your settings open your project interpretor and here all your packages will be present now here as you can see we have beautiful soup 4 so we just click on that and just click okay so these packages will be imported automatically now I have named my beautiful soup as soup and request as you request because I don't want to use beautiful soup and request again and again next also I have used URL lib which is a package now if you're using python 2 you have a different package you will be having URL lip too since I am using Python 3 so this will work for me and then I have an and then I have a function which is URL open so this function will basically import all the dependencies next what I've done I've simply specified the URL which I have to scrap so let me just copy this URL and let me show you what does this explain or in fact if you don't want to copy it just simply type in flipcart.com you can search the product now in my case it's iPhone so as you can see there is a list of iPhones are displayed so here we have all the necessary details of it we have the title we have the ratings we have the reviews we have the price as well so this is all the flip cart page now let me go back to pyam and let's understand the code so here what I have done I have I have my U request which will basically open of the connection and this will grab the web page or the flip cart page in our case and then it will tightly load it and then what I have done I have simply saved it to a variable which is U client after that what I have done I have passed the same variable to the read function so this read function will dump all your data which is gathered and then store the same in the variable which is HT pageor HTML and then I have closed the connection then what next I have to do I have to par my HTML because it's a large HTML file so let me show you the HTML now to see HTML you just have to right click go on inspect so here on the right hand side you see your HTML code now if you move your cursor you will see the left side the pointer will be changing so here if you want to see which part it is showing you have you have this title then if you go down you have the reviews and the ratings and then if you have you'll go down you have the content or you can say the description and after that you have the price so what I have to do I have to first search for the main class in which all these all these features are present so if I go up so this is my main class or you can see the main div class which covers all the element it has title also it has price also it has ratings reviews and everything so I'll just copy this class I'll go back to my pycha so here I have written this I have this pasted this the same div class which is over here so here I have pidu which will help me to pass my H which will help me to pass my HTML and then I've used the function which is find all so here it will find all the div tag which has which is a class now in some cases it may be ID also so here we have div tag which is a class and the name of the D tag and then I have stored it into containers so next what I'll be doing I'll be printing the length of these containers which will basically tell me uh how many products that I have on this web page so I'll comment the whole code for now so here as we see there are 24 products on the very very first page of flip cart so let me show you again so here as you can see there are many products Now using this length function I have calculated that there are 24 products which are displayed on the very first page of flip cart site so this was for the one div class or you say just one container but let's say I have to face details of each product which is present on the web page so what I have to do I have to Traverse the Dom elements so first of all I will first see the containers or you can see the HTML code for the very first index so here I'll be I'll be writing print soup. prettify containers and the first index so pry is a function which is used to beautify your HTML or basically it will bring your HTML in a structured or you can say an organized format so let me just run this whole HTML so here my HTML so this is my basically HTML now what I'll do I'll copy the whole HTML and I'll place it somewhere else let's say I'll place it in my notepad so that we can see it simultaneously now let us try to read this HTML a bit now here first we'll figure out what things we need to scrape from here so here the first thing that it is visible that we need a title of this we need the title of the phone which is Apple iPhone SE space g and it is 32GB now this title is present inside a div tag in inside another div class and then it has a image tab then let's see what what else we can scrape from here so here we have 4.5 rating so this is the rating so we can scrap this as well and then moving on we have the price as well so these are three things that we can scrape we have many more things but for now we'll just be scraping these three things so let me go back to my pyam and let's see what is the first thing that we'll be going to scrape so here what I have done I need a loop for Trav for traversing these elements so for that I have store the elements of containers in a variable called as container so this containers is my main div class which has all the elements present so now what I'll be doing I'll be first printing the title or you can say the product name so for that let me open my HTML so here as you can see in this container I have a div class and inside that div we have another div and inside that div we have an image tag which has an title alt and this is basically the attribute of it so attributes are always written in the square brackets so here as you can see I have print the container and inside container there is div and inside div we have image and then we have a attribute which is alt so let me just print the print this and let me see what what does it display so so here we have the first name or you can say the first phone or you can say the first title of the phone so this is my Apple iPhone SC space that we have already seen in the HTML next what I have to do I'll scrape some other thing like me just Comm in this thing so next I'll be I'll be scraping price so let's see where this price is present so here is my price now I have to see that in which div class this price is present so in this div class which has the title this so I'll just copy this and I'll go back to my code and I'll paste it over here so this is the exact same diff class which I'm talking this now inside this I have container which find all the div which had which is a class and then the name of the diff class now here if you see I have print price z. text now why text because as you can see here I have react ID I have react data react ID then I have react text then have a Rupee symbol and we have many more tags but but this price is not enclosed in any of the tags so for that this becomes my text now similarly I have 21,000 that's text and I have 26,000 and all these things will become as text so let me go back and here I have print price zero which is the first element and then the text so let me just print it for you so as you can see all the text has been displayed so it says 21,000 which has some 19% off and then it tells me the Emi option which starts from this price so this so this is how I have fetched my price now what I have to do I'll be printing ratings as well so it will be the same procedure so first I'll just print I'll just comment the price and for rating let me again go back to my HTML and let's see where is my rating so this is my rating now again I have to see which class it is present in so this is present in this class so I'll again copy this class I'll go to my py Cham I'll write I'll paste this and then I'll say rate container which find all the diff class div tag which has which is a class and then the name of the class here also I've done the text because if you go ahead and see HTML you will see a lot of things you have 4.5 then you have stars and all these things so it will be very easy if you write text so if I go ahead and run this program so as you can see 4.5 star three this rating and this reviews have been printed next I have all the details like title price ratings so let me just print them once again for you so we have we have your title we have price and then we have rating so let me just print it together once more so as you can see I have the title I have the price and I have the ratings so now what I have to do this is showing in my terminal but what if I want to show this in my file so for so now I'll be creating a file so I'll just again comment this and here I'll be creating a file so here I have created a file which is named as products. CSV and then using the open function I have instantiated a mode that is right and then stored the same in F so this F is a normal Convention of f writer then what I've done I have created some headers to it so because CSV do has do have headers so I have added manually heading headings to it so I have written product name or you can say title then the pricing and then the ratings and then I have simply write it so I have these three things for one containers now I have to do the same for all the containers or you can see all the diff classes which is present on the web page so for that I need a for Loop so what I'll do next I'll create a loop now here it will say for container in containers so containers is the main class where all your element is present all your um features are present so here I just I want the same things I need the product name I need the price and I need the rating so here I'll just simply copy the same things which I have already showed you so here for printing the title I have written container. de. image and ALT so have copied it here and then I have saved it into a variable which is product name similarly for product similarly for Price similarly for price I have I'll be copying this thing and this and I'll be saving it to a variable which is price and similarly for rating so here if you see I have added one more function that is strip so strip basically eliminates all your unnecessary commas or unnecessary spaces which are present on the website because every time the spacing is not not present so in this case my extra spacing was there so I have written this strip function so let me now print all of these and let's see whether my loops work or not so as you can see I have the title price and rating for all the products so this is my first product name then I have the price for the same and then I have the rating next I have the second product name I have the price and then I have the rating so similarly we have 24 products ratings and price for the same next what what you can do let's say I don't want the entire price or I don't just need the discount or Ami options that it provides so what I can do I can simply pass my string so let me just again show you so if you see here I just don't need the whole price I just need 44999 but I don't need how much discount it has how much Emi exchange it has and everything like that so that so for that you need to you need to pass your string so here if you see if you see I have passed my string I just remove the comments so here I have first spit my price so for that I have used a function split which will basically split my price prices and then I have again used the same function for the Rupee symbol so here as you can see I have this Rupee symbol and in spite of this Rupee symbol I want to add RS so here I have ADD rupees RS and then I've added the same variable next I have again split it with a e now why e because this because there are some there are some features where it does not provide any discount it just provides your Emi option so here for that just to look a bit clean I have again split it with respect to e and then the final price or you can say the split price is been saved in a variable which is final price similarly I've done it for rating so if you see the ratings as well I have 4.5 I have ratings and then this much reviews but I just need 4.5 so again I have split the string and and then I have stored the final rating in the variable which is final uncore rating now what I have to do I have to concatenate all these three features so I'll be concatenating fin the product name my price and the rating so I'll be concatenate concatenating it with the comma operator now if you see here my now this I'll be storing in CSV as all as well so you should keep in mind there should be no extra commas because every time it finds a comma it will create a new column for it so if you if you look at at if you look it at closely you have product name is this which has a comma as well so rose gold comma 32 GB now for that if you want to eliminate this comma what you have to do you have to write replace function which will basically replace your comma with a pipeline and for final price and for rating it is fine for me so I will simply print these things and let's see what it says so this is my concatenated string since I have not remove the previous one so let me just remove the previous one so that it it will it will not confuse you so let me just commment these and I just want to show the final version which is the concat string so as you can see I have the title of the I have the title of the phone which is this and then I have the pricing and then I have the rating similarly for all the 24 products I have the same next what I have to do I have to put the same in my file also so I'll use the function right and I'll display the same I'll just copy the same frint statement over here and then I'll close my file also so we have already seen the output over here now let's see what this file display so where this file will be created so wherever your project is you will directly go to that folder and the file will be saved automatically so it's in my D drive it's then into iosi and then in the web scraping I have my product. CSV so let me go and click it so here as you can see I have the product name I have the pricing and then I have the ratings so this is what my CSV file looks like now let me go back again to code so as you have seen we have fetched all the details from the flip cart website and these details are automatically fetched and then stored in a CSV file which is named as products. CSV this was the code that we have just discussed so here we have scraped the prices the title and the ratings of flip cart Having learned about web scrapping our next topic is how to make a game in Python you will discover how to use Python to create simple games for the purpose of developing games in Python we need the pame library which is used to create games with the attractive Graphics animation and sounds and also provides the same game experience across multiple platforms and for this we need a basic programming skill now we will see some of the key features of py game first One graphics then events Sound and Music Sprites Collision detection and finally game Loop today in this session we are developing a code for snake game where we are dividing it into our four main parts first one is a cube class second one snake class and then function and finally main function now I will begin with the p game module installation to install py game just type pip install py game hit the enter button now it is showing requirement already satisfied which means I have already installed pame module for those who have not yet installed pame it will get installed in this then to view a py game is properly installed or not just type PIP show P game hit the enter button it will show you the version of P game and summary details as well here you can see name py game and version 2.5.2 and summary python game development and also some other details now for every game at least we need three modules so first one is a pame window second one event handling and third one is main logic behind the game let's begin with a coding for p game window open your visual studio and take a new file let's begin with the coding to import py game just type it as import py game and then to initialize py game do initialize and then now we will declare a variable for screen which defines width and height so for that screen equals Pi game do display do set mode with a 400 as width and 500 as a height just save this file snake game and python okay we are saving this file in the form of python just click on Save now now let's run the code yes can you see the pame window screen which blinks for a second and goes off so to keep the screen on we will write code now let's declare Boolean variable and set it to false done equals false basically we have three Loops in Python but for but for now we are using Y Loop to initialize the while loop we are writing while not done now we will use the for Loop for event handling in the form of for event in py game do event. get method this will iterates over a list of events that have occurred and also next if we have a current event as a quit so which is triggered by the user if that person is clicked on close window so it has to close the py game window so for that if if event. type equals pame do quit then done true this helps in exiting a main Loop when a window is closed and then py game. display play. flip this line of a code helps you P game window updating according to the code changes that you will make just save the code and run it once yeah now you are able to see p game window just we'll minimize this as you all know that the snake game is one of the popular simple game that we were supposed to play in our Childhood Days that to on keypad phones yeah your assumption is right now we are going to develop a same game this is how it looks when I execute the code I can play the game in py game window now basically we are dividing the whole code into four main parts that is first one Cube class snake class function and main function we'll just remove this code and we'll begin with the snake game guys if you want to develop this kind of a game please don't watch take up your laptops and start practicing with me because just watching you can't get expertise in Python so yeah let's begin first we will go through the cube class in this class we are going to declare variable for background board color and position as well first we'll import all the modules which are needed import py game then we'll import import math next import random then import DK enter as DK and then from TK enter import message box now we'll begin with the cube class let's declare class Cube then we'll declare rows and width equal 500 okay now I will Define one instance for cube let's initialize Define initialize start Direction X = 1 Direction so next self dot Position will start and then s s do Direction x equals 1 self do Direction y equals 0 and then self dot color equals the given color so here start is a initial position of a cube and next Direction X and Direction y are the default direction for the moment and then color is a RGB color code for the cube now we will Define the move method for the movement of snake in a Cube's form so we'll Define move method first Define move self in the form of Direction X and Direction y self dot Direction in the x-axis equals Direction in the x-axis itself same as it is for direction y here the move method updates the Cube's position based on a provided Direction either it may be in x-axis or a y- axis which means direction towards x- axis and direction towards Y axis the two attributes are updated and the position is adjusted accordingly next we will Define a draw method which is responsible for rendering the cube on game surface so for that we'll Define a draw method Define draw surface I equals false then this equals self do W which means width divid by self Dot rows number of rows I comma J equals self dot position with a zero self dot position of one now we will Design I on a cube where we can use this Cod snippet for a snake's head so if ice then we are declaring Center variable at as Center equals distance / 2 and then we are assigning radius value equals 3 and then Circle middle and circle middle two are the shapes of I and then we are drawing the circles on the cube surface so this summarizes the functionality of cube class which represents the individual segment of a snake in the game and the next step is create creating a snake class for the snake class snake object here we defined a class with a name snake that inherits from the object class and then initializing a class variable as a body in a least form and turns as a dictionary form now we will initialize a new instance of a snake class with a color and initial position so Define initializing self color and then position and then self dot color equals color and then self dot head equal Cube position and then self dot body do upend self. Direction x-axis = 0 and then self do Direction y AIS = 1 so here for the snake head we are using a cube class you can see here we already defined the cube class with a direction in both X and Y axis next we will write a code for M of snake for that Define move method so to move a snake based on the user input we will write a for loop with the event handling for event in py game do event. getet and then we'll check for the quit event also if event do type equals pame do quit then it has to close the py gim window next Keys equals py game. key. getet pressed method so this line of a code will get the least of members which represents the state of all the keys and each element in the list is either 0 or 1 so to iterate through all the elements of the list we are writing here for Loop for key in Keys now we will see how arrow keys is used in the snake moment so here you can see if Keys Spy game do key left this line to check if the left Arrow key is pressed or not if so then we'll write self. Direction X assigned to minus one so this will set a horizontal Direction and indicating the movement to the left then self. Direction y equals 0 so this line indicates that we are setting a vertical direction to zero which means we are also ensuring a no vertical moment here and the next line self. turns self. H do positions is assigned to self. Direction x-axis and self dot Direction y- AIS this line indicates the turns dictionary with the current position of a snake's head and also the new directions this is used to handle turning points in the snakes movement so we are writing three other form of codes for other three directions with the same logic next now let's write a code to ensure that the snake remains within the grid boundaries so this part of a code handles a scenario when a current Cube does not encounters the turning point it also ensures that the snake remains within a grid boundaries okay so after that we'll write a else part and the else part is to check whether if a snake is moving a left and has reached or crossed the left boundary if that is true it wrap ups the snakes to the rightmost column so for that we are writing code as if C do Direction equals to negative and C do position equals to positive or lesser than zero then it has to wrap up the rightmost or left most depending upon the previous Direction given so I have written a same kind of a code for all other three directions okay let's move forward suppose if you lost the game and want to restart the game on a point of time we just have to reset all the stored values in it right so for this we will write reset method so here you can see defined reset of self and position after that self do head equals cube of position here it will create a new head for a snake at a specified position and then self dot body this line to indicate or to reset the snake's body to an empty list and then we have self. body. append of self. head this will adds a newly created head to the snakes body list and then we should also reset the turns which are stored in a previous game for that we have to write self. turns off dictionary this will reset the turns dictionary which stores the turning points for the snake and also it is important for handling the snake's movement Direction now we are setting the initial direction of a snake move when the game begins so we are assigning self dot Direction x-axis equal to 0 and Y AIS 2 = to 1 now we will write a code to increase the length of snake when snake consumes the foot for that we'll Define add Cube method here we have defined add Cube method and then tail equals self. body of minus one this will retrive the snake's last cube of the snake's body which represents the T of snake and then we have defined Direction x-axis and Y AIS equals tail do Direction x-axis and tail dot Direction y- axis two retrives the current direction of a Tail's Cube then we are checking the condition if the snake is moving right then adding New Cube to the left of the Tails so for that we are checking the condition this and then we are adding tail following this I have written the similar code for all other three directions now we will write a draw method in a snakes class which is responsible for drawing the snake on the game surface so for that so here we have defined a draw method and then for I comm c in enumerate self. body which indicates that to iterate over each cube in a snake's body using enumerate where I is a index and C is is a current Cube and then if I equals 0 this will check if the current cube is a head of a snake or not and then it will execute the else part but here if I equals to 0 if that is satisfied this will cause a draw method of a cube class to draw a head Cube on a game surface and also passing a True Value as an argument to indicate that I should be drawn in the cube then if the current cube is not ahead then it will go for else part and here also it will call the draw method of a cube class to draw a body cubes next we will write a draw grid function which is responsible for drawing a grid on game surface so for that Define draw grid with the width and rows and surface as a parameter then we have written size between equals W divided row which means this will calculate the size of each grid Square by dividing a width of the game Surface by the number of rows and then we assigned x = 0 and Y = 0 to initialize the starting coordinates for drawing the grid and to iterate through the each row we need for Loop so we have written for l in range of rows then we have to update the X and Y coordinates for next horizontal and vertical lines in the grid for that we have written X = X+ size between and y = y + size between after that we will draw vertical and horizontal line using draw doline do method next we have to write a code for redraw window basically redraw window function draws the snake and food on the surface and also adds a grid Clarity and then also shows the updated cubes so for that first we have to define the redraw window and passing a parameter with the surface then next Global row width yes snack or a food we can say here we declared the variable rows width yes which means snake and snack as a global variables and then we have surface do fill with the values which fills the entire surface with a green color and the numbers 0 128 and 0 represents the RGB value for green color next yes do draw we are passing a surface as a parameter so this calls a method draw on a snakes to draw it on a Surface again and then we have snag dot draw and passing the surface as a parameter this calls a method draw on the foood which means snacks to draw it on a Surface next we have draw grid and passing the parameter with the width rows and surface so here the grid is likely used for better visualization in a game and finally we have py game. display. update this line of a code represents to update a display to show all the changes made on the surface and this is necessary for the player to see the updated state of the game now we have to write a code to generate food randomly so for that we are defining here random snack and passing a parameters with the rows and items then to get a body position of a snake we are declaring a position as a variable equals item do body and then to start an infinite Loop to keep generating a random positions for that we have written y true and then we should also generate a random coordinates for both X and Y coordinates for that we have written x equals and Y equals random do Rand range of rows then we have to check for the overlap so we are checking a condition if length of least filter Lambda and the following code this will help in checking if a generated position XY overlaps with any part of this SN back so we are using here filter so using a filter and Lambda to create a list of positions that match the generated coordinates and then we are going to continue this so here we have written continue to just check if there is an overlap and continue is a next iteration to generate a new position or else we have to break and then finally it will return a valid position of x and y coordinate lastly we have to Define message box this function is responsible for displaying a message box using TK inter message box module here we have written root equals tk. TK module so which means this is necessary for creating a TK inter based GUI elements and the next line will indicates that uh this will set the root window to be always on top of other windows and also ensures that the message box will be visible if there are any other windows are open also then we have window. withdraw so this withdraws the root window and this is done to prevent the actual root window from being displayed following this we have messagebox do show information so this is to display an information message box using a show information method from a TK inter message box module and here we are passing sub object and content as a parameter for the title and content of message box next we have written a tri block to attempt to close the root window and also we have written except and pass block this is used to handle the case where if window is already closed and finally the main functionality of code so we have already written a main function this function initializes the game related variables create game objects and runs them main game Loop which also handles the user input update the game State and also check for the collisions and if Collision occurs it displays a message box and reset the game so here we have written Global width Rose yes and snack this is nothing but a we declared a variables as width Rose yes and snake as a global variables as we all know that Global variables accessible throughout the program and then we have assigned a values for width and row as 520 and then we have created a variable wind to display the dimensions as win equals spy game. display. set mode width width here we have declared a yes variable to display or to assign the snake's color and starting position of the snake next we have written snack equals Cube random snack of Rose snake and color off with the yellow color values with this we have created a cube of a snack with a yellow color at a random position that is not occupied by the snake then we have flag equals true to control the main game Loop and then what about time so to control the time frame rate of a game we are writing a code AS clock equals spy game. time. clock module and then we have written while flag this starts a continuous loop that runs as as long as a flag is true and we will add a short delay time to control the speed of a game Loop next yes do move which calls a move method of a snake and also handles user input and update the snake's position then we have written a if condition to check if the snake's head is at the same position as a snack and if that is a true it adds a new Cube to the snake's body and making it longer then a snack is created at a random position ensuring that it does not overlap with a snake and has a yellow color of cube then we have written a for Loop to iterate through the each segment of a snake's body and check if the position of a segment matches any position in the remaining body if that matches then it indicates a self collision and prints the score or displays a loss message then begin with a resetting the snakes position next exit the loop and then finally the game window is redrawn let's execute this code once yes you are able to see the P game window and the snake is moving horizontally from left to right so we'll just play once after exploring game development we will wrap up with the python interview questions you will prepare for interviews with some commonly asked questions the first question is what are the common built-in data types in Python the common buil-in data types in Python are numbers list tled string set dictionary and Boolean coming to numbers they include integers floating Point numbers and complex number list an audit sequence of items is called a list the elements of list May belong to different data types tupple it is also an ordered sequence of elements unlike list tuples are IM mutable which means they can't be changed string a sequence of characters is called a string they are declared within a single or double Cotes set sets are a collection of unique items that are not in order dictionary a dictionary stores value in key and value pairs where each value can be accessed through its key the order of items is not important in case of dictionary Boolean there are two Boolean values true and false now moving to our next question what are the key features of python python is an interpreted language that means unlike languages like C and its variants python does not need to be compiled before it's run other interpreted languages include PHP and Ruby python is dynamically typed which means that you don't need to State the types of variables when you declare them or anything like that python is well suited to objectoriented programming in that it allows the definition of classes along with position and inheritance python does not have access specifiers like C++ public private in Python functions are first class objects this means that they can be assigned to variables returned from other functions and passed into functions classes are also first class objects in Python writing code in Python is fast but running it can be slow compared to other languages that are compiled luckily python lets you use some parts written in C to speed up things where it is really really important important a great example of this is numpy a tool that works quickly because it handles a heavy math task outside of python python finds use in many spares web application automation scientific modeling Big Data applications and many many more it is also often used as a glue code to get other languages and components to play nice moving to a third question what are Lambda functions in Python Lambda functions in Python small Anonymous functions that can have any number of arguments but they can only have one expression think of them as Tiny disposable functions that you create on the fly without giving them a name here is the basic sytax that you can see on the screen for example if you want a function that squares a number you can create a Lambda functions like this you can use Square Five to get the output as 25 moving to our next question is python a compiled language or an interpreted language python Works in two ways partly compiled and partly interpreted when we run our code python first compiles it creating something called bite code then the python virtual machine changes this bite code to work properly on our computer and its operating system moving to our fifth question what are python namespaces in Python a namespace is like a labeled box where python keep track of names you give to the things you create like variables and functions there are four types built-in Nam space holds all the default stuff in Python next is global name space where things you create in the main part of the program Cod third enclosing Nam space if you have functions inside other functions the inner functions can access the outer function stuff fourth one is local Nam space inside a function python creates a separate box for its stuff think of Nam spaces as organized boxes where python STS your stuff based on where you create it it helps python keep track of everything you have made moving to our sixth question what are local variables and Global variables in Python moving to Global variables variables declared outside a function or in a global space are called Global variables these variables can be accessed by any function in the program for example you can check this code this code initializes a global variable X to Zero then uses a function increment to increase its value by one by employing the global keyword increment modifies the global X ensuring it affects the variable globally the program first print X as zero then calls increment and then prints the updated value of x as one demonstrating how a global variable can be modified and accessed throughout a program coming to local variables any variable declared inside a function is known as local variable this variable is present in the local space and not in the global space for example you can check this code in this example the local count is a local variable defined within the show count function each time show count is called local count is initialized to Zero incremented by one and its value is printed the local variable scope is limited to the function in which it is defined so it gets reinitialized with each function call demonstrating how local variables maintain their scope and are not preserved across function calls moving to seventh question what is self in Python self represents an instance or object of a class in Python it is explicitly included as the first parameter but in Java it's optional it serves to distinguish between a class methods and attributes from local variables in the init method self points to the newly created object while in other methods it points to the object that called the method moving to our next question how are arguments passed by value or by reference in Python in Python arguments are passed to functions by assignment which is often described as pass by object reference or pass by sharing this means that the function receives a reference to the actual object not a copy of the object if the object is mutable changes made within the function can affect the original object however if the object is immutable it cannot be changed within the function any attempt to modify it will result in the creation of a new object leaving the original unchanged moving to our ninth question what is a pass in Python to pass signifies executing no action or serving as a placeholder within a compound statement it essentially indicates a blank space where no specific action is required or written you can check this code in this code the do nothing function uses the pass statement as a placeholder indicating that no action is taken when the function is called the PA statement is useful in scenarios where a statement is syntactically required but you don't want any command or code to execute effectively serving as a do nothing operation moving to a 10th question what is dynamically type language dynamically type languages are languages that do not require any predefined data type for any variable as it is interpreted at runtime by the machine itself in these languages interpretors assign the data type to a variable at runtime depending on value moving to 11th question what is pep8 Pep stands for python enhancement proposal it is a set of rules that specify how to format python code for maximum readability moving to the next question what is python path it is an environment variable that is used when a module is imported whenever a module is imported python path is also looked up to check for the presence of the imported modules in the various directories The Interpreter uses it to determine which module to load moving to next question what are python modules name some commonly used build-in modules in python python modules are files containing the python code this code can either be a function class or variables a python module is a p file containing executable code some of the commonly used built-in modules are os CIS math random date time and Json moving to next question what is break and continue in Python the break statement is used to exit the loop prematurely when a certain condition is met the continue statement is used to skip the current iteration of the loop and continue with the next iteration you can check this example in the first Loop when I equals 3 The Brak statement is encountered and the loop exits in the second Loop when I equals 2 the Contin statement is encounted and the loop proceeds to the next iteration without executing the print statement for two moving to the 15th question can we pass a function as a argument in Python yes in Python you can pass a function as an argument to another function this is possible because functions in Python are first class objects meaning they can be treated by any other object such as an integer string or List you can assign them to variables store them in data structures and yes pass them as arguments to other function check this piece of code in this example shout and Whisper are functions that are passed as arguments to the greed function the greed function then calls the pass and function with a name argument demonstrating how functions can be dynamically passed around and invoked within python now moving to our 16th question what is Hash symbol do in Python hash is used to comment on everything that comes after on the line hash symbol in Python is used to denote commands for example hash this is a single line command in Python this line is not being executed when the python runs the code moving to our 17th question what is Type conversion in Python type conversion refers to the conversion of one data type into another int converts any data type into integer type float converts any data type into float type or converts characters into integers hex converts integers into hexadecimals o converts integers into octal tle this function is used to convert to a tuple set this function Returns the type after converting to set list this function is used to convert any data type to a list type dick any function is used to convert a topple of order key value into a dictionary Str Str it is used to convert integer into a string moving to the next question what is dog string in Python in Python a dog string is a string literal that occurs as a first statement in a module function class or method definition its purpose is to provide documentation about the object such as its purpose usage parameters return values and other relevant information dog strings are typically inclosed in triple quotes and can span multiple lines they serve as a form of inline mentation and are accessible throughout the object's doc attribute doc strings are essential for code readability maintainability and understanding as they help developers and users to understand how to use and interact with the code effectivity moving to the 19th question what is slicing in Python slicing is used to access parts of sequences like tles and strings the syntax of slicing you can see on the screen let start end step the step can be omed as well when we write start end this returns all the elements of the sequence from the start inclusive till the end minus one element if the start or end element is negative I it means that the ith element is from the end the step indicates a jump or how many elements have to be skipped moving to the 20th question what is pickling and unpickling the pickle module accepts any python objects convert s it into a string representation and dumps it into a file by using the dump function this process is called pickling the process of retrieving original python objects from the stored string representation is called unpickling now let's move to the intermediate level questions explain inheritance in Python inheritance allows one class to gain all the members say attributes and methods of another class inheritance provides code reusability and makes it easier to create and maintain an application the class from which we are inheriting is called a super class and the class which is being inherited is called the subclass or child Closs or it is also known as derived Closs there are four different types of inheritance supported by python single inheritance multi-level inheritance hercal inheritance and multiple inheritance when it comes to single inheritance where a derived class acquires the member of a single super class multi-level inheritance a derived Class C is inherited from Base Class B which is derived from class A hierarchical inheritance from one Base Class you can inherit any number of child losses coming to multiple inheritance a derived Closs is inherited from more than one base Closs does python make use of access specifiers python does have mechanism for controlling access to attributes and methods of objects but it does not have explicit access specifiers like some other programming languages such as Java or C++ in Python attributes and methods can be accessed freely from outside the class definition unless you explicitly make them private conventionally attributes or methods that start with a single underscore are considered to be protective meaning they should be accessed only within the class or by subass attribute or methods that start with double underscore are considered private and a name mangled meaning the names are changed to include the class name making them harder to access from outside the class discuss different ways of deleting an element from a list there are two ways in which we can delete elements from the list one is the remove function and one by using the pop function let's check the remove function first the remove function deletes a mentioned element from the list the pop function delete the element mentioned at specific index from the list how are classes created in Python in Python classes are created using using the class keyword followed by the class name and a colon inside the class methods and attributes can be defined the init method is a special method called a Constructor used for initializing newly created objects here is a basic example in this example my class has two attributes attribute one and attribute two and one method as my method the self parameter is a reference to the current instance of the class and is used to access variables and methods associated with the current object moving to the next question write a program in Python to execute the bubble sort algorithm bubble sort is a straightforward sorting algorithm that repeatedly steps through the list Compares adjacent elements and swabs them if they are in wrong order the pass through the list is repeated until the list is sorted although it is not the most efficient algorithm for the large data sets it's a classic example for learning sting algorithms let's take this example to understand bubble sort we have a list of numbers here in iteration one first the Sorting will compare 11 and 7 we can see that 11 is larger than seven so a swapping of the positions are being done similarly the bubble will move forward and it will compare 9 and 15 since 9 is already smaller than 15 there will be no change and similarly the process will go on after that for the iteration two we have 11 7 9 15 23 21 and 26 again the same process will continue the number of iterations will take place until we have a fully sorted list over here you can check the code for bubble sorting the program first defines a bubble s function that takes a list array as its parameter it then uses two nested Loops to Traverse the list and compare each pair of adjacent elements if a pair is in wrong order either the first is greater than the second the elements are swapped this process rep repeats until the entire list is sorted finally the program demonstrate using the bubble sort function with an example list of integers and print the sorted list write a code snippet to generate the square of every element in a list if you want to generate the square of every element in a list you can use list comprehension in Python which is a concise way to create list here's the simple code snippet to achieve that the code takes each number in the numbers list squares and then the squared value are collected into a new list called squared number when you run the code it will give the output as 1 4 9 16 and 25 moving to the next question write a program to produce the fibon series in Python the Fibonacci series is a sequence of numbers where each number is a sum of the two preceding ones usually starting with zero and one here is the code and let's understand how it works we first start with the first Fibonacci numbers which are 0o and one then in each iteration starting from the third term we calculate the next Fibonacci number by adding the last two numbers in the series we appen the new calculated fibon number to the list we repeat this process until we have generated nend terms in the Fibonacci series finally the program takes user input for the number of terms and prints the Fibonacci series up to the number of terms what is the difference between a shallow copy and a deep copy the difference between shallow copy and deep copy is primarily about how they handle these nested objects a shallow copy creates a new object but instead of copying the nested object it just copies the references to them this means that the original and the copy will share the same nested objects changes to the nested object in the copied object will affect the original object and vice versa however changes to the container object will not affect the other can create a shallow copy of an object by using the copy method a deep copy creates a new object and recursively copies all the objects it contains unlike a shallow copy the copy and the original do not share any nested objects changes made to any level of the copied object will not affect the original object and vice versa you can create a deep copy of an object using the copy module's deep copy function write a program in Python to check if a sequence is a palent room a palindrome is a sequence of characters which reads the same backward as forward examples of palindrome include words like radar or level or numbers like 1 2 3 2 1 or sequences of characters that form the same sequence in Reverse to determine if a sequence is a palindrome in Python we can write a function that compares a sequence to its reverse if the sequence matches its reverse then it's a palr this program defines a function is palr that takes a SE sequence as input and returns true if the sequence is a pent room and false otherwise it works by first converting the sequence into a list to ensure the reverse operation Works uniformly across different types of sequences like strings and tles then it compares the original list with its revers version to determine if the sequence is a palent room moving to our next question how is multi-threading achieved in Python multi-threading allows different part of program to run simultaneously making the program faster and more responsive multi-threading in Python is achieved using the threading module which provides a way to create and manage threads threads are smaller units of execution that runs concr within the process pythons threading module allows you to create multiple threads each performing different tasks simultaneously here is a simple example demonstrating the usage of multi-threading and python this example we create a subass my thread of threading out thread and override its run method with the code we want to thread to execute we create two instances of my thread start them and wait for them to complete using the join method meanwhile the main thread continues to execute this program will output the message from both the threads concurrently how is memory managed in python python utilizes a private Heap space to store all objects with the python memory manager overseeing different aspects of this Heap Heap including sharing catching segmentation and allocation control over the Heap remains solely within the python interpreter leaving users with no direct access or influence over its operation whenever python exits why isn't all the memory deallocated python does deallocate most memory upon process exit but there are scenarios where memory may not be immediately reclaimed due to the factors such as garbage collection overhead external resource management and memory leaks however from the perspective of the operating system all memory and resources allocated by the python process are eventually reclaimed when the process exits now if you want to know more about garbage collection overhead external resource management and memory leaks then you can refer a Python Programming certification course the link to which is in the description box below which is faster python list on nump Aras and why numi aray are faster than python list for numerical operations numpy an open source Library designed for array manipulation in Python furnishes efficient functions for numerical computations on arrays the swiftness of numai arises from its implementation and C which facilitates quicker executions compared to python list python list being implemented in Python and interpreted language lack the speed advantage of nump AR operations which is executed in a compil language what is the process of compilation and linking in Python in Python compilation and linking process are somewhat abstracted from the developer due to the nature of of the language being interpreted rather than compiled however there are still compilations and linking processes that occur behind the scenes when working with python modules especially those containing C extensions or when used external libraries coming to compilation for Pure python code there is no separate compilation step python code is compiled to bite code by the python interpreter when it is executed however when using python modules containing C extensions there is a compilation step involved these C extensions need to be compiled into machine code that can be executed by the computer's processor compilation of C extensions is typically handled using a compiler such as GCC on Unix like systems or msvc on Windows moving on to linking after the compilation of C extensions the resulting object files need to be linked together to form executable files or shared libraries during the linking process references between different object files are resolved and necessary libraries are linked to the final executive or Library linking is handled by the Linker such as ID on Unix like systems and link.exe on Windows how to add new column to Panda data frame adding new column to Panda data frame is being demonstrated in the following code the code import the Panda's library to create a data frame from the dictionary that Maps first and second to the panda series with specified indices resulting in different length and NN for missing values it then adds a third column to DF using a new series with values 10 20 30 indexed by a b c the attempt to add a fourth column aims to the sum of the first and the anonymous reference into third which would sum values from the first and third columns the code Imports the Panda's library and creates a data frame from the dictionary data info that Maps the first and second to Panda series with specified indices resulting in different lengths and NN for missing values it then adds a third column to DF using a new series with values 10 20 30 indexed by ABC the attempt to add a fourth column aims to the sum of the first and an anonymously referend in for third which would sum values from the first and third columns the code concludes by printing DF after each column Edition demonstrating how to dynamically expand a data frame now let's finally move to the advanced level interview questions and here it comes the first question from advanced level write a code to sort an array in numpy by the N minus 1th column you can sort a numpy array by the N minus 1th column using the num. ERG sort function to obtain the indices that would sort the array along the specified axis here is how you can do it the column will output the original array and the sorted array based on the N minus oneth column firstly it selects the last column of the array then it Returns the indicis that would sort the last column of the array ARR sort SED indicis uses the sorted indicis to rearrange the rows of array based on the Sorting from the N minus one at column how do you compute the ukian distance between two series to compute the ukian distance between two Series in Python you can use the skype. sp. distance module and here is how you can do it in this code we import numpy as NP and the ukian function from the ci. spatial do distance we Define two sample series series 1 and Series two as nump arays we use the ukian function to compute the ukian distance between series 1 and Series 2 finally we print the computed ukan distance between the two series how do you get the items not common to both series a and series B to get the items that are not common in both pandas series A and B you can use the pandas series. Isen method combined with Boolean indexing this method allows you to filter out the items present in one series but not in other you can then concatenate the unique elements from both series to get the full list of items that are not common to both here is how you can do it the script perform the following step firstly it uses a do I and B to find elements in a that are not in B and vice versa for B do is in a it then concatenates the result not in B and not in a into a single series containing all unique items not common to both original series finally it prints out the concatenated series containing the items that are not common to both A and B the result will be a series containing all the items that are unique to each series effectively showing the items not common to both A and B what is flask and explain its benefits flask is a microwave framework written in Python it is classified as micro because it is lightweight and requires minimal setup to get a simple application up and running but it is also extensible enough to support complex applications as well flask provides the tools libraries and Technologies necessary to build a web application this framework allows you to build web applications rapidly with minimum lines of code it is a modular and flexible design making it adaptable for developers to tailor the applications with the required components coming to the benefits firstly it comes Simplicity flask straightforward and easy to understand syntax makes it accessible for beginners the framework is easy to set up and get started with which is ideal for a small project or when learning web development Basics then it comes to flexibility unlike more comprehensive framework that dictates specific ways to achieve task flask is unopinionated about how the things should be done this flexibility allows developers to use the components they prefer and structure the application in the way that works best for them third one is lightweight flk does not automatically include tools and libraries that your project may not need making it very lightweight and efficient its Simplicity and lack of overhead make make it a performant for many types of objects then it comes to extensibility while flask is minimalistic out of the box it can be easily extended with a wide variety of extensions available for task such as validation user authentication database integration and more this means you can start simple and add more functionality as needed lastly it comes to the robost ecosystem despite its Simplicity flask is supported by a large and active Community there are numerous extensions and packages are available that can help to add functionality to flask applications quickly is Jango better than flask D Jango and flask both serve to translate URLs or web addresses inputed into browser into python functions flk offers a more userfriendly experience than Jango but it requires you to Define more details yourself as it provides less outof boox functionality on the other hand D Jango automates many aspects of web development reducing the need for manual configuration Jango comes with pre-existing code that users need to understand while flask gives users the flexibility to write their own code potentially making it simpler to learn each framework excels technically and comes up with a unique strength and weaknesses what is the use of sessions in Django framework in Django framework sessions are used to persist information across user request enabling the server to remember data about a user's activity and preference es the mechanism is crucial for functionalities like user authentication where sessions keep user logged in as they navigate different parts of the web application sessions also show user preferences or shopping card contents enhancing the user experience without compromising security as the data is stored server side Jango simplifies session management by providing a secure and customizable system that can use various backend to store session data making it a powerful tool for developers to maintain the state and us a specific data efficiently write a oneliner that will count the numbers of capital letters in a file your code should work even if the file is too big to fit in the memory so first let us check how normally the code would look like in this code we open the file file.txt in read mode we iterate through each line in the file using a for Loop for each line we iterate through each character using another for Loop we check if each character is Upper Keys using the is uper method if a character is Upper Keys We increment the count variable by one finally we print the total count of capital letters in the file now the equivalent oneliner this one liner does the same thing as a previous code but is written in a condensed form using list comprehension and the sum function it iterates over each line and the character in the file checks if the character is uppercase and sums up the count for the upper kease discuss Jango architecture Jango follows a model view template architecture which organizes web applications into three main layers model view and template the model layer represents the applications data structure and interacts with the database using jango's object relational mapping which is also called as or model Define the data schema including Fields relationships and behavior allowing developers to work with database records as python objects The View layer handles the application's business logic and user interaction views receive HTTP requests process data from the model layer and generate HTTP responses they encapsulate application logic handling tasks such as data retrieval processing and rendering use interact with the modeler to retrieve or modify data and use templates to render Dynamic HTML content for the user the template layer manages the presentation of the data to the user templates are HTML files with embeded template tags and filters that generate Dynamic content based on the data passed from the viewer Le jango's template engine supports template inheritance reusable templates and Powerful template tags for processing data and rendering HTML output list out the inheritance Styles in Jango in Jango there are three main ways models can inherit from each other the first one is abstract based Clauses the second one is multiable inheritance and the third one is proxy models coming to abstract based Clauses think of abstract base classes as templates for other models they don't create their own tables in the database instead they're like blueprints that other models can use you mark a model as abstract by setting a special attribute to true in the model's meta class coming to multiable inheritance multiable inheritance is when you create a new model that is based on the existing one and each new model gets its own table in the database Jango makes Separate Tables for each new model and these tables are linked together this type of inheritance lets you add more features to an existing model without changing it directly to use multi- inheritance you just make a new model class that is based on the existing one coming to proxy models proxy models are like Shadows of existing models they have the same fields and methods but you can change how they work in Python without affecting the database they don't create new tables they just act as alternative views of the original data proxy models are handy for adding extra functionality or organizing code without changing the original database structure you can create a proxy model by setting a special attribute to true in the model's meta class these different ways of inheritance gives you flexibility in how you organize your models and customize their behavior in Jango each one has its own purpose and advantages depending on what you're trying to do with your models create a program to add two integers greater than zero without using the plus operator you can add two integers without using the plus Operator by using bitwise operations here is a Python program to add two positive integers without using the plus operator this program defines a function add without plus that takes two integers A and B as input and return learns their sum without using the plus operator it uses bitwise operations such as and zor and left shift to perform addition bit by bit the program prompts the user to enter two positive integers and then displays their sum how to save an image locally using python whose URL address I already know to save an image from website using python you need to know the web addresses of the image with python you can use a library called request to download the image from the internet then you can store it on your computer and here is how you can do it we use the request library to fetch the image from the web addresses you provide if the image is successfully downloaded that is status code 200 it gets saved to your computer with the name you choose if there is any problem with a download or saving process the program will let you know you are required to scrap data from IMDb top 250 movie Pages it should only have Fields movie name EO and rating to gather information from IMDB's top 250 movie page you will need Python and some tools like request and beautiful soup and here is how you do it we import the necessary libraries request for getting web data and beautiful swap for sorting through HTML we Define a function scrape IMDb top 250 to fetch IMDB's top 250 movie Pages pick out the movie names years and ratings and return them as a list of dictionaries inside the function we use request to get the IMDb page and Beautiful soap to handle the HTML content we Loop through the table ruls on the page extracting movie details from the appropriate cells we remove any extra spaces and formatting from the extracted data and store it in the dictionaries finally we call the function to get the data and print out the movie titles ears and ratings how to send an email in Python language sending an email in Python can be done using the build s smpp lib library for SMTP which is simple mail transfer protocol and email library for composing and formatting email messages here's a basic example how to send an email in Python firstly we imported SMTP lib and relevant classes from email. my module set up the senders email addresses receiver email address and email password then we created a my multiart object to compose the email message said the sender receive and subject of the email we created the body of the email messages and attached it to the my multiart object then we connected to the SMTP server login to the sender email using SMTP authentication then we send the email using send mail method of SMTP server object then it handle exceptions and close the connection to the smtv server using the quit method create a program to convert dates from year month day to day month year you can achieve this conversion using the datetime module in the python here is a program to convert dates from the format year month day to day month year we Define a function convert date that takes a date string in year month day format as input inside the function we use date time St strp time to pass the input string into a daytime object specifying the input format then we use St RF time to format the daytime object into a string with the desired format we handle the case where the input string is not in the correct format by using try except block finally we test the function by taking user input for a date string and printing the converted date how you can get the Google catch age of any URL or web page to find out how old a web page is in Google catch using python you can send a special request to Google cat server and here's a simple way to do it we create a function called get Google catch age to find out the age of a web page in Google's catching we send a special request to Google cat URL for the web page we are interested in we analyze the response from Google to extract the age of the cached web page if everything goes well we return the catch age otherwise we show an error message finally we set the function by asking up for a web page URL and printing out the catch age information with this we have come to the end of the session I hope you have enjoyed the video and if you did make sure to hit the like And subscribe thanks for watching and keep learning I hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist And subscribe to Eddie Rea channel to learn more happy learning