Transcript for:
Python Programming Session 3 - Operators and Data Types

foreign [Music] and welcome to the session we are going to talk about uh you know session three uh Concepts before I get into that let me tell you that this specific program is aligned with B Tech in data science and AI program and uh we have ensured that we included a lot of additional information so that people who want to pursue and become a successful data scientist or a data analyst or rather a data engineer right it will help them a lot and for people who want to build web applications and mobile applications for them also it is going to be very helpful and so that's the rational with which we got started uh with respect to this Python Programming session and uh you can go to 360digitmg.com and there is amazing resource here called as mind map when you do a drop down you would find Python Programming fundamentals just click on that you can expand collabs Etc we have yesterday spoken about arithmetic operations we have discussed relational or comparison operations and um we have also spoken about assignment operations and uh yeah we have also spoken about logical operations our goal is to ensure that each time you know we get a chance we keep building on top of these you know mind maps keep adding more and more information so that it can serve as a ready reckoner for you okay and python or any programming language can be learned only when you practice so please practice to gain sufficient expertise just by watching the videos you will not learn you need to get your hands dirty you need to get your hands on all right all the best for your learning let's move on so yesterday if you remember we have discussed until here and today we are going to talk about identity operators anything that you write after a hash within python e is called as a comment so this is a comment anything that you write after hash is called as a comment for example you make a note on your book when something is discussed on a book you make a note right of what what is being taught on similar lines instead of writing notes on your book you can make a note directly on python code be Jupiter or spider or Google collab doesn't matter but if you write anything after hash that is called as common and [Music] why in Python sorry Y is python here you have some syntax warning warning messages can be ignored you need not worry about warning messages it just says instead of ease you could have as well used double equal to it would have done the same job just telling us did you actually mean double equal to by saying is Yeah we actually meant that but that's fine we just want to use ease rather than double equal to so why is python no why is y right how can y be python so the answer for this should be false one is one oh yes absolutely if the left value is equal to the right value you get true 2 is 1 how can 2 V 1 right so if the left value is not equal to the right value then you get a fox then you have python is python we have already discussed that python is case sensitive we already discussed that python is case sensitive what does that mean here you have P which is in lower case here we have PE which is an uppercase lowercase and uppercase cannot be the same so python is python it's false obvious one e0 no the value on the left is not equal to the value on the right hence 1 is 0 is also going to be false once again I repeat that warning messages can be ignored now one is not equal to 1. rather than writing not equal to I can write in English language as well 1 is not equal to 1 No 1 is equal to 1. if you say 1 is not equal to 1 then that's a false statement hi hello is a string whenever you have a string or words or alphabets you put them in double quotes so hi hello is not hello hi yeah it does not seem right hi hello so here also it should have been hi hello but here you have hi hello here if you have hello hi then both are not the same is not I hello is not hello hi yes that's true Okay so another thing is we have something called as complex numbers where you have the imaginary component and the real component when you say print two plus three J it's going to print the result here and if you ask python on what is the data type what is the type of this when you have these kind of representations right wherein you have the real component and imaginary components then the type would be called as complex it's very complicated it's kind of that complex then we also have Boolean type whenever you write something off the hash it has no impact on the output it would not appear in the output it will not have any impact and uh the only reason why we put a hash and write something is for our own understanding it's like Boolean type it's for our own understanding when you say Bowie and then it is true or false true false I call as Boolean values when you say type of true it says it's a buoyant type boolus just an abbreviation then type of false also says that it is [Music] that's about your identity operatives is is not this is what we are spoken about or discussed about now let us get into membership operators and here in the mind map also we have the membership operators in not in these two are called as membership operators when I say why in Python do you have y inside this python yes we have you see why is that so the response will be true thank you do you have l in Python no we do not have we will have L we don't have p y d h o n nowhere we have l so the result will be false next we have p in Python observe carefully friends here P here is in lower case but in Python here p is in uppercase and python is case sensitive what does that mean this P lowercase is not equivalent to P in uppercase so the result will be false again here p is not in Python so here p is in uppercase If You observe it but here in Python p is in lower case so the result will be true why true because it's uppercase p is not in this lowercase p is in this uppercase p is not available in this so the answer is true okay and here are the various operators exponential we have already discussed about this complement is Delta the symbol till done on your keyboard you will have all the numbers one two three just to the left of one you will see this tilde symbol then you have plus minus multiplication division modulus flow division addition subtraction right uh you have right left bit wise shift bit wise and or regular or comparison operators equality operators assignment operators identity operators membership logical so on and so forth a lot of operators exist and we have already discussed about quite a few operators and whenever you evaluate these operators and if you have an expression which contains more than one operator then the order of evaluation the sequence of the order in which you evaluate depends on the order of the operators okay so operators are evaluated in this way using a specific rule called as PEMDAS with parenthesis is given first importance we'll do it practically we will solve it hold on I understand you might be having a lot of doubts hold on exponentiation multiplication division addition subtraction so P stands for parenthesis e for exponentiation M for multiplication B for division e for addition and as for subtraction that is how it has to be evaluated so parenthesis has the highest president precedence okay and can be used to force an expression to evaluate uh in the order that we want all this is Theory we will get into the practicals explanation next next these two then if the operators have the same precedence then they are evaluated from left to right [Music] so that means if you have two divisions two dividend symbols like this 9 divided by 8 divided by 1. both the divisions how do they prioritize from left to right so as you prioritize this you calculate this then you calculate whatever result you get from this you divide that with money that is how it works okay and then we have a lot of data types within python we will also talk about these data types in further detail there are primarily five data types which are available in path numbers and within numbers you have integers float and complex values integers means they will not have any decimals throat means they'll have decimal values and then you have complexity then you have Boolean Boolean means true or false then your cells sets are nothing but collection of elements like 246 when you're mapping our dictionaries it's something like one is marked to a I mean two is smart to be in that way and then you have sequences sequence means sequence of alphabets it could be list sequence of elements or it could be a tuple which is also sequence of elements what is the difference between list and a tuple Etc we will talk about that so now we will take it slow I think uh we have a lot of theory but then I'll just skip this part and we'll get into the practicals integers integers are plain numbers okay and if you say print of one it will just give you one when you say print two plus four you are adding two integers then you get the result as six when you say print 12 multiplied by 3 you get 36. then simple if I were to run it I say control enter and you get to see the results if you're using MacBook command enter would give you the same result here we are assigning a value 15 using assignment operator to a variable called a so what will happen eventually a will contain this value when you say type of a then you get integer integer is a Time because it doesn't have any decimal warning right if it has decimal then it will be called as float then again we are looking at so anything that you write after hash is a comment for your own understanding you can write anything after a hash when you say print 11.5 it's going to print the result here onto the output here we are taking a value using an assignment operator we are assigning it to an object sorry a variable or object X now if I say print X it would show me what is there in x and then if you say type of x it says it is float float means decimals do you see a decimal value here absolutely we see a decimal here is 0.45.5 so this ease of float data type then yes Boolean type when you say Boolean means true or false we know that when you say type of true you get green when you say type of false true means one false means zero and when you say 2 plus 2 what will you get true means one right usually 2 is equal to 1 false is equal to 0. so true plus true means 1 plus 1 which would give you two plus two plus false plus false is nothing but 1 plus 1 plus false is 0 Plus 0. when you solve it you get to 2 so this is how we you know perform certain operations now let's look at this is some data types numeric data types now let's look at sequential data types in sequential data types you have lists list is an ordered sequence of items remember it is ordered sequence of items and the items are always represented within square brackets you'll ask wave brackets the values in the list the values within this like if you have one two three Etc the values within this list are called as elements or items so these are called as what elements or items it can be written as a list of comma separated items so absolutely one comma two comma three items in the list can be of different data types it can be alphabets also it can be float values also and the values of list are mutable mutable means it can be changed what do you mean by that can we look at practicals absolutely okay so let us get into the prime tickets here is the distance a list data type is given in square brackets and each element is separated using from so here we are using the string name of the person come on here we are giving again a string which is alphanumeric it has alphabets it also has numbers but you are representing that in single quotes always string has to be represented in either single quotes or double quotes Etc then you have numbers 2013 2018 Etc what we are doing is we are creating a list of elements or items and then we are assigning using this assignment operator to a variable or object called list list one then if you say print list one it will show you whatever is part of list one so your list one contains all these four so those are up here and when you say print length of list one length of this it's saying that let this 4. because it has four elements you can access the values in this variable if this is a variable which contains all these elements or items you can access these elements or items using the index numbers remember one thing friends indexing in Python starts from zero what does that mean if I say which is a zeroth element it will refer to this first what is the first index number index number two is this index number three is this indexing in Python starts from zero why is it that way whom should you ask the founder of python who is the founder of python Guido van Rossum probably you can go contact him somewhere on LinkedIn Etc ask him hey why do you put it in this way wherein indexing starts from zero if you have any such questions please so you have length of list which is four elements only if you use print wherever you use print that is going to give you an output onto the console okay next you know how to execute each and every block or cell of code just control enter how to access values you know since it's all indexed if you say go to list one and refer to the index number 0 index number 0 is the first element so this would predicate result when you say friend list one go to this list one and I want the index number three zero one two three so index number three will be this so it would print out this result as 2018. when you say print list one colon 3 colon 3 means start from the beginning colon means start from I mean to the left of colon you don't have anything if you don't have anything python will start from the start that is it will go from 0. 1 [Music] and this last number is ignored okay last number is completely removed just give me a minute let's check here I would quickly check the internet speed just to ensure that I fear the doubts this is the internet speed that I'm using it's almost 14 Mbps which is considered to be fairly good speed if you are not able to see the video that means there is some issue at your end okay so both the download speed and upload speed is up to the month or it's much better right than usual standards so I request you all to please check the internet connection at URL and maybe there is some issue at the RN or maybe the internet bandwidth is low so you might feel that the video is not of uh it's not clear but that's not the fact majority of you all who have decent internet connection will be able to receive okay all right so this print list one colon 3 colon 3 before colon you do not have anything so it will start from the beginning 0 1 2 and this last number is ignored two things that you need to remember within python one is indexing starts from 0 this is 0 this is one two three indexing starts from zero number one you remember that number two whenever you have values like this the last number is ignored it is not consummated so here this would actually mean 0 1 and 2 index numbers 0 means first one means this 2 means this so this happened if you want to print the list in the reverse order if you want to print it in the reverse order what we are doing is you type it in this list one list one contains all these values if you just say -1 it is going to print all these index values in a reverse order foreign so sorry I didn't run this line so it's from there we go right so what is it doing now minus 1 starts referring from the back okay it will start referring from here and then it will print all the values so 2018 gets printed first next 2013 next 360 digit mg next this is how it is printed okay next functions in list data type let's understand this as also okay and we are going to understand about something called as append and remove append is adding new element to the existing list say you have created a list you are naming it as previous these variable names that you have here you're calling it as P list here you are calling it as list one these names can be anything of your charts it is not mandatory to give only these variable names or object needs it can be anything absolutely okay you can even say ABC or you can call this as Xyz your wish you can give any usually a name which is logical makes more sense okay next so we are creating a specific list of elements or items if you have numbers you need not put the numbers in single quotes or double quotes not needed but if you have string or alphabets then you need to certainly put that in single quotes or double quotes so you have x y z ARA ABC Etc that's a list that we created when you say dot append 2009 and when you say now print the a list I mean ALS will give you all the elements or items of that list when you run this what happens is it will print all the values one two three x y z one two three x y z ABC all of these in addition to that it is also taking 2009 and printing it up so it is appending to the list that you are it is appending you can also remove elements for example here you have 2009 what are you seeing go to this list dot because now this a list has 2009 also remove that remove would remove that element from the list and now when you say print of a list you don't have 2009 because you've removed it from your list okay then pop will remove the element from existing list [Music] when you say pop pop out in some sense right So when you say pop what it would do is it is going to remove the last element from the list so now this alerts contains all these elements one two three X Y Z's ABC Etc when you say go to this playlist now which contains all these elements and say dot pop and open closer brackets what this would do is it would pop out the last element what is the last element here is so that is now when you say now show me what is there in a list when you say print A-list it will give you one two three x y z and Zara the first three elements ABC you already pumped it out there so that won't be there okay okay next when you say Taylor's now this A-list contains all of these one two three x y z and and you know that within python indexing starts from zero so when I say index number 0 it would refer to one two three index number one will refer to x y z index number two would refer to design all right and now when I say print a list dot pop zero means pop out index number zero if you don't give any index number it will pop out the last element the last element is pop out however if here your exclusively saying pop out index number zero and index number 0 is 1 2 3 which is popped out if you say print let me see which is the you know popped out element it says one page now if you say now show me what is remaining in a list print out the results it says x y z and z because it takes number zero one two three you pop it up now let us create a new list we're just giving it some name guys [Music] you can give any name you can also give your name for that you can say equal to I mean you can use [Music] what are we doing here we are adding certain elements to this list using one two three comma x y z command right Tommy comma ABC comma 1. this is the list that you have when you say go to this list and insert in the third index position value 2009. which is a third index position this is index number zero index number one index number two so here is where you want to add 2009 and after that when you say print a list it will show you all the elements of a list so you have one two three x y z Tommy and 2009 is now there in the third index position so this is index number of zero index number one index two index number three of course index 4 and minus 5. in this third position we have 2009 you can also extend the list one after another very simple in order to extend you just need to give a plus sign or multiplication sign so on and so forth that means here we are creating two lists one list as elements one two three x y z Tommy ABC one we are creating another list deals in which you have 2009 binary so there are two lists that we have created when you say print a list multiplied by 2 what are you expecting as a result it would repeat itself twice so a list has what one two three x y z from me ABC one since you are multiplying it with two you want to repeat the same list again one two three x y z from E ABC one uh friends I'm sure you're hosting certain questions on your YouTube chat certain things are not very clear I request you all to ask your question and also put your phone number I just sent you that maybe or or your email ID whatever you prefer so that we might respond to you with that with that specific response because it becomes very difficult uh while I'm doing this in parallel looking at the chat messages becomes very difficult I think yesterday or in the previous session there was a question on can you also show us pie charm sure so first let us get uh familiarize with uh Jupiter then I'm also going to show you spider and Google color we've already seen so I'll try and show you a few other things but it doesn't matter friends whether you write on your book with blue ink pen or black ink pen or red ink pen doesn't matter ultimately you just want to make a note it's like that Python Programming can be written on Google collab or spider or Jupiter or pie charm it doesn't matter okay as long as you're just interested in writing python code okay so your questions are well taken now we'll make a note of that but certain questions might be dioces we might not understand clearly you might say hey can you repeat it so instead if you can give your phone number or email ID along with your question it makes a life easier right we will arrange someone to call you and understand your question and then you will respond to that okay so this would give you this as an answer and when you say a list plus b list so you have list of elements here in Eagles you take all of those plus the biggest in b list you have things 2009 and when so you have b list plus b list now I'll have to I think run all these clients to connect now here if you say a list dot extend the b list what happens let's see you have Alice which has all these sentiments using dot extend with the elements of b list extend this with the elements of b list if you were to just run it it just extends so what it does is it takes a list all these elements five elements one two three four and then it is extending this with the elements of means we discussed 2009 means okay what is the difference between extend and append let's see now if I were to run this what did you do it has taken your tailors which contains all these elements and when since you have told append not extend you're saying append so it is taking the b list values and both these b list values are together going to be one element together this would become 1 11. so how many elements are there now one two three four five six seven and eight these two together is one that is a different sense that is a difference between extent and abundance see we are learning we are discussing a lot of things the only way to remember these things is through practice you need to start typing the more number of times you type better for you all to practice this is like any new language if you want to learn German language just by reading a word once you might not remember we are not rajnikanth Robo right to just scan the book and then remember everything for the lifetime we are not robots so the only way to remember is through practice so whenever you see a piece of line I request you all to type and that is how you are going to learn that's the only way to learn any new language it could be German Spanish French any language including this this is the only way out there so you have b list b list contains these two elements when you say dot extend ALS what will happen so this b list a list elements will be added and if we were to print a list and then see what is there in the list it will show you the result so what is it doing you're saying extend s Alis contains all of these okay and you're taking b list and extending so you have b list and then you are extending the A-list to that okay I'll talk more about this there is uh some dot dot and then it's getting extended Beyond a point but I'll talk about that so what is happening here is when you say print a list it would print you all these values okay and what happened here suddenly might be a question I see 2009 Benelli and then again I see one two three right I see x y z Tommy ABC all of these things again and that's getting this extended and when you look at the Beatles contained earlier only 2009 and well now it's showing you all the other values that is it is taking this A-list elements and then it's showing up all those elements as well okay so let me do one thing let me once again in the intros s yeah I'll talk about these things tomorrow in further detail so slowly will understand it why is it doing the way it is doing Etc will understand now if you want to type something in reverse order can I do that so we are creating a list of elements or items in which you have one two three four five elements when you say print of leaders it would show you all the values which are ingredients and when you say A-list dot reverse it would print the values in reverse order okay and then you're just printing star star and then underneath that you want the a list values so let me run it on the next two [Music] okay so what is happening here is you have created a list with elements or items using print a list which would show you all the elements of this then you are saying a list dot reverse so all these are calculated in reverse order that is three four two and all of them but then before you print the reverse elements you're just issuing a function print star star just for the segregation after this you have this just to say we give you and then you're saying print a list [Music] which is giving you now the list of elements which are printed in the reverse order 342 ABC time next stop uh see friends the best practices always after comma give a space one best practice another best practices after you have a variable give us peace then assignment operator equal to 10 USPS don't mix it like this don't have it like this it won't throw any error but if you're typing in this way it is not best practice best practices your speech language you might ask me hey why is it important see friends when you attend interviews obviously the first round of interview will be verbal they'll ask you questions you answer most often than not for data analytics for data science or for final programming Etc the assign your task and they expect you to write the program or code when you write a program or a code they expect you to follow best practices supporting best practices are always good to be followed [Music] it's going to help you guys immense so we are creating a list of elements 8 99 45 33. and you're saying first sort the values sort them and then print them in reverse order first thing that we will do is I am going to remove this reverse equal to 2. okay and then we will run it what happened all you're saying is I'm creating a list of elements I am sorting them when you sort it is going to sort of ascending order so first eight I mean and then you're saying print the sorted values of beads first aid then 33 then 45 then 99 this is in ascending order ascending on but if you want to print them in descending order then what do we do we just type reverse equal to 2 that means you want to print the numbers in reverse order descending order 99 45 33 and 8. there is another way of sorting the list let's understand this way also after comma giving a space is according to the best practice so you are creating a list with all these numbers or elements elements or items are available four items or four elements are there in this particular instrument when you say soldered of this biggest what it does is it's going to sort these values in ascending mode okay this will sort the values in assembly and then using the assignment operator we are assigning these sorted values to an object or variable called sorted underscores now when you say print and show me what is there in this you get on this all right so this is another way to start next count the value in given list of elements how do I do it say you're creating a list of elements or items using assignment operator you are assigning all these to a variable computers so you have one two three inches so these elements uh you created a list and you are assigning it to this when you say print a list dot count okay so you are saying go to this list and count how many times Zara appears how many times R app is one sentence programs so print the result onto the screen so you have to so print number of times Zara appears with students um and when you say find the value in the list so you're saying go to this list what is the index number of Zara though you have multiple you have Zara here and Zara here also okay you can either represent them single quotes or double quotes your wish doesn't so index number zero index number one index number two so the index number of Zara is two you might be having an interesting question if I want the index number of Zara here as well as here because this is index number zero index next number zero one two three four and five you have Zara in two places index number two and five this specific function is stopping the moment it sees the first match at the first match Zara Zara it stops and says index number two but what if I want the function to Traverse throughout and also print me the index number of this hour we'll learn that also but slowly and steadily we will learn there is no rush how do we concatenate tools this is something which we have already seen if you say e list plus b list and you are adding the elements of a list which are all of these with the elements of b list which are all of these foreign and using assignment operator you are assigning it to an object called new list now when you say show me the elements of this new list it has all the A-list elements and it also has D list elements [Music] okay so let's run it now if you see what is the type of this A-list or b list or new list what is the type of plant it would say that python would say that this is list [Music] of all the elements that's it it's a list so list is always represented using square brackets and all the elements would be there in this you can have numbers and string values also within a list when you say hell of less it could show you bunch of arguments a bunch of additional reading stuff upending clear copy count extend index insert pop remove rewards sorry it just contains a lot of additional information [Music] now sorting quickly we will do this and I think we'll have time to do only this thing you are creating a list of all these numbers and you're saying sort without a print statement if you want to see the result then it will show you the result in the output only if this is the last line this is not the last line if it's not the last line you need the print so using this line of code you're sorting all the numbers then you are saying print those sorted numbers so the things are sorted in ascending order you have that then if you say print the length of these numbers one two three four five six in that way if you want to see those it says that 13. you have 13 elements if you want to see the maximum value in this list then you say maximum value which would automatically pick the maximum value and sure the maximum value is 86. and when you say print the minimum value in the list it will calculate the minimum value and show you the minimum okay so this is all we had for today and uh please please ensure that you answer the questions which are posted on our LinkedIn uh page and we will also help you all get a certificate joint certificate of nascom and 360 digit energy you receive a certificate from nascom and 360 digit mg provided you answer whether it is right or wrong doesn't matter you answer all the questions which are posted on our LinkedIn page [Music] please do that and we are going to keep a track of people who have answered all the questions whether it is right or wrong doesn't matter you attempt it in the first place and will give you an opportunity to get the nascom certificate and 360 digit MD joint certificate so what are you waiting for please answer the questions we will post the linking questions on the YouTube channel also please follow our company page okay and help us help you thank you so much and do subscribe without fail to our YouTube channel thank you all friends bye see you tomorrow