[Applause] [Music] [Applause] [Music] okay so I'm I'm getting started right now so welcome everybody to another um class session this will be the third class guys just give me one moment all right so I welcome everybody to today's class and then I hope that you all had a great time the last class even though it seemed technical for people that are just getting into this language uh but I'm going to do a recap myself for the things we talked about in the last class uh before I do that I would like you all to come so if you've got one or two things to say um concerning what you learned in the last class or your um feedback um can we get that so sure around and I'll allow you unmute your mic so anybody we got anything to see um con the last class I like recap anybody um okay I don't think anybody is ring his hand so um let me just myself so in the last class we introduced us to the the Python programming language right and right out of the Gat we start by saying python is an interpreter not a compiler and that implies that um python reads your code line by line so if I start off by saying print um um print lello word and the next line I say print um end of code it's going to do this just the way I wrot it okay so um some little tips about um Jupiter notebook oring Jupiter notbook is that in coming here to click on run you can just press shift and enter and then it runs and take you to the next cell so as you can see there's just one cell right now but of course going forward I need to write another code and I need to open another cell didn't manually what I would have done is press run okay then opens another one but rather than doing that I can just you know press shift shift and Enter key on my keyboard and then it runs that code and then opens a new cell immediately so I think this more efficient start coming to time to click on run here okay so what I was trying to point out is that things are done line by line as you can see it printed h word first and then it printed um the end of the code okay um so that was the first thing we said we also said that indentation matters so if you attempt to put some indentation here for some reason it's not going to run right so it's going to give an error because it's not expecting any indentation here but we say that indentation between text doesn't really matter so if I come here and then put some spaces for whatever reason I don't know and I run my code it's going to run the same way okay although this is not the best practice best practice always to leave no space between the function and then the arguments okay so um this is the function print is a function okay when you're calling a function you use parenthesis so I want to call the function name of the function um say for instance print is a function and then I open and close the parenthesis so inside this parenthesis I take my arguments they call it arguments okay so um in the pre statements one the first argument you take is just the object you want to print so the object I want to print in this case was l and that's why I typed L word in the second case I wanted to print end of code and that's why I typed end of code so anything I want to print is what I'll put first here right okay um going forward I also explain some of the other arguments you can Define in this print function but I don't get I don't to make things too complicated right now so I wouldn't talk about them just it um yeah so that's that and then we also okay so some are waiting let me admit all okay all right so um we also spoke about variables and variables are very important um things in in Python because they are like Point outs to objects okay so you store objects in the variable um I I use the scenario like you have a book and you're keeping your book in a bookshelf okay um so you can see variables as a bookshelf although that's a simplified explanation if you're looking at the concepts in an object oriented manner which I don't want to get just it um you wouldn't call the variable the bookshelf rather you call the variable a sticker to show that this these are books okay so well you can see variables like that so you may not see variables as a container although yes they are containers to store some things uh you can see them as labels to that container okay so we'll go we'll go further and the reason why we actually do that let me just say because if for instance I I have a variable a and I called it um I called it name I'm right now okay and I call it and then I want to check where this variable is stor what I use is the ID function okay so I use the ID function to check um where this object is is stored okay I said object than variable and I really don't want to complicate things but let me just say right now that everything in Python is an object so I may use object variables interchangeably that because everything basically everything is an object I'm going to get to that when we um get into object oriented programming which is a vital Concept in in any programming language whatsoever uh but I don't want to get things um I don't want to go so um complicated just yet so I just have to say I just I just have to say that right now that everything in Python is an object so a variable is an object so anyway so um I'm going to use the ID function like I said and then I've called I've written the name of the ID function but to call it I have to open and close the parentheses like I've explained earlier so I open parenthesis and automatically it closes it so this ID column is just um used to check the location okay where this vable is stored in my computer okay or where this object is stored in my computer I'll rather say that way okay so um let me check where this object is T so I pass in argument a which have defined up so if I do that you realize that the object is stored somewhere here in my computer this is like a location right or a memory in my computer okay well um if I come right now um and then I call another name um this time let me call you glory because that's I'm seeing my screen and let me print now because okay U let me say this automatically right Jupiter notebook prints the last line you right if it's a line that can be printed jupter notebook print it okay automatically but if you're working with other IDE you have to explicitly type print for it to printed your screen okay so I needed to say that so um so I print again um B um okay so I print B the ID of B so I want to check the memory location of b um and then if I do that you see that it's quite different okay so this was start somewhere here and this was somewh and that's because these are two different objects okay they are two different object but if by any chance I change this guy okay I Chang this guy to the same um you can see that there are different variables but the object itself are the same okay if I now check the ID notice what what do you notice now where they are stored is the same they stored in the same place that's why I said variables can be seen as stickers or as libels because although they are different variables they are the same object Okay so this was just a scenario to tell you that um variables are not really um you can't call them the bookshelf itself you can just call them stickers to show what's inside the inside the bookshelf okay so yeah that I just wanted to say that that was not part to say okay so uh we talked about variables and I said they just way of storing um objects in Python okay so um next also we talk about various um data types um we have in in Python okay we mentioned the integers and those are just old numbers okay so you have something like let's say number number is equals to two Okay we check the type we use the type function to check what kind of data type they are so if I check type of number it's going to tell me this an integer okay um we also said you had floats let me just call it varable so I don't have to be changing up and down so if I put like 3 2.43 for instance and I check the sorry I was wondering what happened now look at what happened python because the first one was number okay and I still use type of number it was still giv me data type of that number right that's because that number has been stored somewhere already in my program even though it's not here anymore that's one about notbook um in other I think vs code once you once you remove that it will tell me number not defined it give me a name error okay but in notbook he has sted it somewhere and it's still going to put number even if I have removed number from here so the mistake I made was to of course change this back to to variable so now you should give me a float and I can see it gives me a float so we also said you had strings okay and strings just involve letters okay that's how I'll put it letters and then you define strings using um apostrophe okay you define strings using apostrophe you can use single apostrophe you can use double whatever one works okay okay so um in fact you can put a number for instance if I put number like this all right um because I have opened this apostrophe is going to see this as a string so if I print it out you can see it gives me which is a string but um you can also use letter so you can you can use something like um I'm see Felix screen so I'm printing Felix and let's see Felix is um has type of a string so um what the last we mentioned was a type I think you use n often because when you start null missing values you would use non a lot so I print that tells me tells me that a non type variable okay um then we went ahead to also talk about data type um or data structures U and data structures are just what you use to um I put it to contain more than um maybe one object okay so for instance if I want to um have I want to store the names of people in a class um I can't start calling the names one after the other so what I use I use lists okay so I said the three major data three major data um structures we have we have lists okay we have dictionaries we have sets Okay but you mostly use list and dictionaries okay so this is a list for instance so um list can take more than one elements or more than one object so they are um separated with commers so first to create a list I told you that you have to open square bracket like this all right and then once you open the square bracket you can now passing number of elements you want in your list or however you want it to be in your list so let me see I just want to create the uh a list of people in this class for instance Okay so take my first name um because name has to be a string I must open um sorry I must open an apostrophe like this okay if I pass my name like this um python will see this as a variable okay python will see alab right now as available even though alabu contains um letters okay so if this must work it means I have to Define allab to be somewhere maybe before I I wrote that I must say maybe alab is equals to maybe let say two okay so if I run this right now it w give me any error because I've defined alabi okay but if I had done this right it will give me an error because first python doesn't know what alab is it's seen alab for the first time right so rather than doing this I can just encapsulate this in apostrophe so this way now it l as a string okay and not as a variable okay okay so um I also want to put other names there so is waiting actually that's why I'm seeing his name okay so I put aded so I put T because is also waiting um and okay I'm see put okay um I put as well okay okay so um let me just leave these things um okay I think these are good okay so um what I have just created right now is a list and I store that list in a variable called names so if I want to print all the names in my list I just call names of course and then it print it out for me as you can see all right but if for instance I just I just care about the first name in my list or any one element in my list what I have to do is what we call indexing okay and in indexing what you do is that you call that list first off but you know that if I print it like this it's going to print everything so if I want to print any specific one I have to you have to index I have to show the index of that list I have to show the where exactly that element is so if for instance I to print the first elements this is the first position but recall I told you that python starts to count from zero okay so uh it starts to count here from zero so this is zero take this out okay this is um where am I okay this is zero this is one this is two and this is three okay so this is the way python index indexes so if I come me and say I want to just print the first one I just put index of Zer then if I run this it's going to print straight away okay so if um I perhaps I care about starting from the end okay and I want to print um say the last number I told you that when you're starting from the end python starts from negative one okay and so if I want to print that what I do is I start from 1-23 sorry yeah yeah I was correct 1 -2 ne34 so you want to print again but assuming I'm starting from the end what I do is negative4 okay okay um so if I run that I'm sorry1 telling me out of range is it3 just give a moment -1 - 2 - 3 oh guys I made a mistake you guys didn't tell me I was wondering what was going on okay what happened was this right I opened my par is I didn't close it until I got here so python is seen Tai as one as one element okay that's what happened and that's why it was telling me out of range because I was wondering what exactly was going on okay so because I didn't close my parentheses on here python saw this thing here as just one element okay so if I'm to fix that I'll just come here and put one and then call me and open another one okay okay so I think that's Prett good now so if I run this it gives me one element and so I can do my4 again and then it print 11 okay so that's the idea of indexing and I hope everybody is following this just um is just a recap of what we did in the last class okay and I also mentioned that um there may be situations where you want to PR from one element to to another element okay and so to do that use what we call slicing okay and in slicing what you just do is that you indicate your starting and ending elements okay so for instance I want to print from to my starting index will be zero right so I start with zero and then I separate my starting and ending with a column okay so now the next thing is to put my ending index if I'm stopping at my ending index here is um right is two okay because of course z one two so if I run this it's going to actually stop at T remember I I said okay thank you I'm strong for pointing that out now remember I said when it comes to range python takes off the last element okay so if I run this right now it's going to take off this last element and stop at T okay so if I run this right now you can see stop at T if I put three okay it it now stops at so this syntax of of python I think it's important for you all to know that okay um so we went on to talk about operators in Python because most of the time you dealing with a lot of operations know and then of course you know the basic ones I do for instance um one okay this system okay so 1 + 2 2 + 2 I run that going to give me four okay if I do 2 - - 2 it's going to give me zero okay I can the division so divided by by four give me 0.5 um I can do what else multiplication so multip by um four it's going to give me eight so I can do all of this stuff all right but there are two other um operations I want to in it to and that's um FL and then when you're doing FL what it does is that um when it checks it prints out the remainder of the division so this is like a normal division so you can do FL division for instance you want to doid now 8 is what noral right that be two that be two two okay but if I do the FL it's going to PR just a remainder okay so it's going to just remainder and you can see a print to okay maybe I should make it um 10 so it to make more sense so if I do normally 10 / 3 is 3 remainder one okay so if I do this it's going to now if I care about the quent if I care about this answer what I do is I I use the percentage sign okay so this is they call it modulus so this one just prints out the whole number involved okay so if I do that it's going to print one let me know if I'm making sense um let me know if been following me oh okay great great um great so I think um then we also spoke about of course exponential so if I want to do like two power five can do two ra to power will be multiplications multiplication sign twice so I do multiply multiply by maybe five and that gives me the answer now recall that this is happening because I am using D or normally I should put print statements in all of these things if I go to vs code and type this it won't run it's won it won't print anything it will run but it won't print anything out it don't give you any feedback um because I didn't put a print statement a print statements is just what you use tell the python to oh show me what's going on show me the answer to this right um said something FL gives answer and percentage Yeah gives Remer yeah FL gives answer gives yeah yeah is that what I said oh I think I I up something well thanks for that okay yeah so actually this gives the whole number right okay yeah this gives the whole number this gives the remainder okay this is flaw this is modulus um yeah so I think we are good with that right okay so um what else would you check about yeah okay so now that was for list and we also mentioned that you have you can perform different functions to a list okay so a list has different functions or call you Call some methods okay um so for instance you want to add an element to a list use theend function appen method not function okay so for instance I had my list already my list was names of course so names now if I want to add one more name to this list okay I need to add a name to the list I found out that add a new comma and I need to add his name to my register I use the pen function okay so um the function you can check it out it takes the object so it append object to the end of the list append means add okay so it adds that object to end of the list so now my object just be a string of the last name output so let me I to put M um yeah so I put M right now sorry spell your name wrongly it has it will change my list and add M to this so what I can do now is to print names so if I print names you can see okay I can um know remove that name back and I use the pop method so the pop just remove the last name in the list okay so if I write the names back you can see is gone okay so you have many other many other methods you can use and I told you one thing you can do is to put the D di function and you pass the data type for instance it prints out the different methods you can use all these um for now don't bother about them because they call them um they special methods but for this one you can append these are the ones you care about right you can append you can clear you can copy you can count you can extend you can index insert pop remove reverse sorts so all this you can do to this object which is a list okay um yeah so that's that um lastly let me just talk about dictionaries because they are so very key um when it comes to data structures okay so dictionary is a is a special data structure that has to do with you having a key and a value okay so just way you have dictionaries English dictionary where you have a name or a word and it's meaning in same way in the dictionary in Python you have a key all right um and a key is just what you use to find the value so you have a key and then you have a value and then I said in Python you def find with um qu braces okay so you open a braces like this it means wow I'm going to define a dictionary someone is waiting I can't see anybody waiting okay waiting all right so um you have um to to create a dictionary of course you use uh you use CRA like this you open and close it now the first thing is to define a key okay let me just all this dictionary a okay okay so um let's say I want to get I want to um have a dictionary that store the name the email and the phone number of people okay all right so the first thing I will store is what the name so I'm going to store name like so yeah but I made a mistake here I didn't put put thisy guy in apostrophe and so he's going to assume that name is a variable which of course is not so I should I put them in apostrophe like this okay that means is Str okay um my okay yeah so I split key and value with this column as you can see here okay so the next thing now is to Define my value now I can just Define one name like this David um right this will work fine I let go on like this okay so I've defined one key and one value okay so now let me go on the next thing is to Define email so Define email like this and then that's my key of course my value will be let me say David Gmail okay um let me also add an age yeah because that's a fantastic thing to put so h of course would be a an integer it can't be a string so let say David David is 12 years old um what else can I put okay I think it's good that way so I think um it's good that way so I've defined um a dictionary to store this information name email and H so if I run this right now it has been stored this dictionary has been stored in variable dict a now if for instance I want to access David's um I want to access the name or right I want to know the name in my dictionary what I do is that just way I do indexing in lists I also Index this guy okay so of course how do you do indexing a list you open a square bracket right you open okay indexing this is slicing but yeah the same idea so you open the square brackets okay so I open a square bracket like this and then I pass the key okay so if I want to check the name for instance I pass this key so I come here and I paste it paste like so and if I try to check this out it tells me oh this key or the value to this key is D so umary just a way of using something to access another thing okay but now let's assume I have more than one students is not the student right so what I can do is that I can put this in a list form so I put them in square brackets I can add mon right now so I have David um I have I'm just on my screen so I'm going to put his name again um I have okay and then let me for a sh name okay Toby I don't know I like Toby okay so yeah I have that and then now let me update their email so add Gmail okay let me take this out it's confusing me okay so yeah okay now interestingly I didn't pass this as a list so that's a big mistake so I should take pass this as a list not a string anymore okay because I'm taking more than one email so I pass as a list so I go on at gmail.com and then lastly I do Toby at gmail okay so for their age um I have 32 sorry I have 10 I have 91 okay so these are their ages so if I come right now let me run this to store it back I make a mistake my syntax oh yeah I didn't pass it as a list am I making I pass list okay so if I run this it run successfully and I come here and check for my names you can see it prints what this names now if I care about again the first name what I can do is I can Index this lists just way I do indexing our list so I have taken this and this gives this gives me what my list of names if I now care about this first name David what I can do index this by putting another square bracket and passing it position which is zero so I run this accuse meid now I can s this for email accuse me that's okay I care about the email of everybody gives me that as a list okay so you can do a lot of stuff with dictionaries in fact you can create tables which we will call data frame when we get into using of Panda's Library okay so you can create your tables um maybe you want to create a data set yourself from dictionaries all right you can create fantastic tables and you can work with tables right with dictionaries so they are very important stuff when it comes to data science and I think it's important for us on this for a while you also have sets you won't use set often the idea of set just remove duplicate also a collection of data so let's say in my name for instance I have twoa if I pass it as a set it's going to take it out it's going to take out one and just give me one that's the idea of a set and then you define sets with craes yeah but in case of dictionary where you have key and values inste you just have values so these are my values copy it paste it okay and then so you can see set as lists but list without any duplicates okay so if I run my set one um I run set one like so you going to see gives me the same thing just we list anything you can do with a list you can do with a sets but if for any reason I had two to and then I create another to right now and then I run the sets you can see that still it just gives you one so the idea of set is that it takes out what duplicates so anywhere you see an element appearing twice you just take it out um take out but if was this was a list for instance so let me change this to a list don't coll is to square bracket um square bracket like so if I run this you can see that my Toby appears twice you can see I think this guys are going to take us off in next one minute uh but it's important to do all of this recup so um in today's class um I'm going to talk about control flow I think is also a very important Concept in in Python um because it kind of guides how your program runs so the idea of control flow is that do this only if a particular statement is um met or a particular condition is Mets so the first control flow statement we be talking about is the if else statement so I think these guys are okay I guess it's making sense right okay great now the last um control flow we are going to talk about is white Loops okay um white Loops are they operate like four loops but white Loops don't iterate or they don't Loop over iterators okay so um for white Loops white Loop basically run automatically it runs continuously until a condition is met okay so in four Loops what you do is that you Loop over list but in y Loop We Run The Thing continuously until a loop is met until a condition sorry is met so now um let's say you want to do the exact same thing we did here want to create a list from 0 to 14 okay the first thing is to First create an initial number so you can just say I okay we call I zero of course you create empty list too because um so let me not let me call it list two okay um create list so to create that my while loop I'll say while I is less than 10 oh okay I did 15 so let me 15 okay so while I is less than 15 what I can do is my list two do append append I just the same thing here right the same thing here okay so next thing is if I wrun this code for any reason it would be an infinite slope because I will continuously be zero I Define my initial I to be zero right I said let I be zero I said when I is less than 15 now I will always Z will always be less than 15 so if I for any reason run this code it should just be adding Z Z Z to this list till I run out of memory and my system crashes or something okay so it's always good to watch out for infinite Loops okay so how make this thing robust I have to find the way of increasing I now the way of increasing I is to put um this how do do I is equals to okay I Plus+ one so now once I do this it means that after this line after he has appended the first I which is zero it's going to increase I by one so the next I be one so it's going to check again is I is one less than 15 yes it's going to continue continue continue continue increase that ey until it gets to 15 so once it gets to 15 now check it's 15 less than 15 definitely not so since this condition is no longer true it's going to break out of the loop okay so it's going to stop appending I and then I can now come here outside the loop remember and print my list this times it is two so I run that can see a printed the same same thing printed here okay I hope that makes sense said can't index it like we did to others um can't index it like we did to others I didn't get um I didn't get that well the idea of while loop is that you are not actually looping over something you are just doing something until the conation is meant okay that's the idea of w Loops okay so for instance say you're creating a game and you want maybe you want some to guess a number and he want to guess a number maybe five times so you you do you put all your codes inside y Loop and you create a counter so once that counter is equals to five you break out of the loop okay I I don't think you can do that for with four Loops because for Loop will just iterate over in listate over an iterator but in W Loop while loop will continue to run continuously they can most of the time they can do the same thing right and actually for Loop is shorter to do things like it's looping over something but while loop also has it place when you want to run something automatically or you want to run something continuously until a condition is met so um really um you wouldn't do indexing like that you just create this condition can be anything okay it can be anything in fact I can call this through that's interesting thing now if I say something like while true what we happen is that it will do this forever okay it will do this thing forever so how do I um break out of this loop I cannot put an if statement okay so after my increment after my increment so while true means continue to do this forever so you print it adds I I was Zero it does that increase one it continues adds uh now I is one he adds one to the list he continues adds one again now I is two it puts two to the list and continues this forever now how do I break out of this Loop so flexibility Loop you have to use an if statement because you want to put the condition so you want to put that say if I okay is equals to let me so it doesn't confus you so if is less than 15 okay if this guy is 15 break out of this Loop now break is a key word I was planning to talk about break later but I think it's a good time talk about it so break is just a keyword to break out of the loop on your own maybe you just want to create something and then you want it to break once any particular um condition is me use the break statement okay so once this guy sees this break statement is going to break out so I I run this um zero um wa a minute so I'm should do that okay I guess I should put this here somewhere let me see okay graci said he just she just run an infinite slope what you do is that you just have to um stop your Kel okay so what you do is come here all right in the Kel and stop it so that's I did so it can be very crazy run so um let let me see how to fix this because if I actually run this without any of this stuff it's going to be an infinite Loop let me try it out if you guys can believe me so I'm going to this and then I run you can see it's an infinite Loop this a means this code is loading it's still running okay that's many of this here and then uh yeah it can happen you can see maybe your computer out of memory and then it's telling you that you have overworked me so that's why you have to be careful of infinite Lo and for me I can just stop this because this once I stop this can see just give me the error that I interrupted it so that's an infinite um do an INF I'm trying to see how to fix this was less than 15 so it really got at the first instance of the index it just broke out of the loop straight away because of course z was less than 15 so I should have put if it was greater than 15 okay that the mistake I made um so if it was if it's greater than 15 um at that point then it's going to break up and that's why you can see that happen okay so um we have less than a minute so guys it's unfortunate but we'll stop here tomorrow I'm going to talk about a very interesting concept I think we've talk about control FL all which is great um for W and E statements that's fantastic so tomorrow we going to talk about object oriented programming now it's like a fundamental concept when it comes to program because if you know it it's going to help you a lot and then once we finish that we can now go to importing models and once we are done with that we are done with python and then we can now move into libraries like NPI and fers which are most of the things you would use when it comes to science so I'm hoping that you guys had a great time today and then if you've got any questions unfortunately I'm to take that question because I have less than a minutes but if you got any question please drop them on the group your fellow um fellow your colleagues can answer you and if you don't I can answer you you can also send me a pastor message and I would answer you [Music]