Transcript for:
Understanding Python Lists and Operations

[Music] welcome back aliens my name is Ivan jetty and let's continue with the series on Python so we have done with the basic thing right we have installed this office and we have done some operations and work with variables in this video we'll walk with a pond set bonus list now to understand this what I will do is I will open my ideal as usual what I want to do here is we want to work with least right now it is list let's imagine you have different values and let's say you have numbers and you have strings now if you want to group them together now if you have worked on arrays in any other language you know C C++ or Java we have the same or similar stuff in here which is a list now how do we use this it's very simple actually let's say I have some nums okay so we have this video because nums equal to and now we can assign the values I should have assigning one value we can assign multiple values now there's a question how will I assign multiple values so let's say 25 12 now in this case we need to use a special symbol or special character we just called square bracket so we have to use square brackets here and in this square bracket you have to mention the values okay now which one anybody doesn't matter so I will say 25 12 maybe 636 maybe 95 14 so we I got these values now this are the list of values which I have here now you might be thinking can we only have similar type of data examples all these things are numbers right let's try that as well so I will I will say enter here can I print it we can so simply type nums and you've got the value you can see we call 25 12 that is 695 and 14 that's so simple now if you remember in the last session we have also talked about string and we say the ok string is that collection of characters and we can pick up individual character with the help of index value right can we do it here and the answer is yes example let's I want to pick up the first value which is 25 in this case you know the answer right so we simply have to send nums and 0 and oh it worked you can see we've got 25 let's I want to fetch the last value which is nums of 25 right so OH 4 because the value the size of the list is is 5 typos doesn't matter so if I say enter you can see record 14 so it's working we got 14 as well okay so we got 25 we got 14 so first and last is working in fact not just the first and last you can pick up any value right what if you want to print something in between and then till the end like remember in stringers also we have done that so example I want to print though that it meant fourth and fifth so third and then to the end so of course we can do that you can start with two which is third element and we can give a colon and there is no end limit right so if I say enter you got a data element food and filt now what do you think can be used negative numbers the way we have done before you know the the index number as negative 1 minus 1 minus 2 minus 3 yes it works here as well so we can say lumps of so if you want to pick up that 14 bits there which is at the end you're right we have to use minus 1 and it works if you want to fetch the first element we have to say minus 5 right that's what we have done before so yes we can use negative range as well okay how about having a string or another adder here on another list year with synonyms with some names and names of so what names so I can have any name sale right I can have naveen I can have children and I can have let's say John so if we call this three names here right and now might I say enter you can see we also have a list of string and if I print names you've got the names there okay so now if you can see one array which numbers we have second derivative names which is of string we can get a different list of different types now can I get a list of different types I mean one list and different types I will simply call it as values equal to and I want to have a double value here example the first one I would say is 9.5 which is a float value then I want to go forward a string go with my name and then let's say another another one which is 25 which is number right so we have a float number we have a string and integer number if I say enter it works okay so we can have a list where different above data and that's the beauty about this you know you can have different theta and that's not the case with other languages right in C C++ Java what we do is when we create an array it has to be of same type yes in Java we have the object area but okay let's not let's not discuss that here if you're already thinking about Python this is we have so we have a list where you can have different types can we have two lists working together and something this I want to get another list year mil is equal to miscellaneous things so I would say mil is equal to I want to have at least off list if we do that let's try so I want to have this list which will have numbs and which will also have name so a mil will have names and numbers and names and oh there's no better okay I will say mil okay you can see we quite a list and inside that list we have two different lists one is of numbers and one is of string okay that works so the amazing thing about list is we can perform certain operations because it has certain methods to use right or you can call them functions now how do we know that so what i will do is i will send nums dot now I'm going to say now start of course we have not got though we got the pop-up there can you see that now you can see we got up and we got clear we got copy count extend index we can use all these functions let's try now the another thing about list is it is mutable or what is that new table simply means you can change the values and we can do that here nums dot append I want to append I what I want to append let's I want to append 45 and now if I say nums or you can see we got 25 12 and then at the end we got 45 so we can append it what else we have so if I so if the pop-up is not coming instantly you can simply say control space okay so we got create as well so clear will clear the entire list for you try it out we know events you're watching this video try it on your machine different different operations so we have inserted right or we can also use insert now difference between a pair and insert in append it will append at the end in insert it will it will add in between let's try so an insert what we do is we specify the index value as well so I can say index value 2 comma I want to specify there let's say any value let's say 2077 I will say enter and now if I drink num so you can see we got 77 at index number two now what if you want to remove the element even that is possible you can say num start these are metal colors to remove and in remove you can pass the element which you want to delete I will say I want to delete 14 enter and if I say numbs you can see in the list we don't have 14 now what if you want to use index number oh we have not done that right because when you pass 14 that's a value so if you want to delete based on the index number he was that is simple you just need to use a metal ass pop so you have to say num start pop inside this pop you just past the index number which one which I want to do little eight seven delayed twelve so in this case I will pass one and you can see record twelve out how do I verify if I say num so you can see we don't have to well now okay in fact we can also use pop without and index value what happens when you when you use pop without index value now if you have learned the data structures before we have a concept of stack which is last in first out which simply means we have these two methods there which is push and pop so push is pushing the elements in this stack pop is removing the element and when you say pop it will remove the last element which is added so in this case the last element which is added is 45 which is at the last I would Center you can see the got 45 so if you don't specify the index value you caught the last element so you can use this when you implement stack in data structures yeah okay so we can use a move we can use pop in fact we have another method you know if you want to delete multiple values not one multiple values how will you do that so in this case you will use del so that is a again a command and then you have to pass the name of the list which is nums and in the end you have to specify the index value from where you have to start I want to start from that say 2 and then I want to end it I want to delete all the remaining elements you know so I will Center and if I when you find now you can see we got only two values leave 0 and first because firms - everything is deleted so that's how you can work with noms now time you let me just add some values there oh how do i how to add multiple values now because I want to add multiple values right not one in that case you can use another method which is called as extend again you need to read documentation from this so there is one question from everyone you know so I'm going to learn after wait to read it of course you're watching this video but reading is also important right what if I say Python has this amazing documentation online so just need to go to online and search for Python Docs you will get the documents in fact in the next video we are going to talk about how to use the help command which is very useful actually so we'll see that so if you want to add multiple values just type nums dot extend and in the bracket specify multiple values if you want example I want to add 29 comma 12 again 14:36 i want to add this four values we have done a mistake okay I guess we have we have to give a square back here as well oh so that was a mistake we have to put that oh I didn't Square back it my bad and if I send numbs you can see record devalue so we got at least now now with this list we can perform some inbuilt functions you know we in Python we have this inbuilt functions now how do I know that which inbuilt function we have mainly have max we can find some so we have those methods here so let's try so can be used in build met inbuilt functions let's try so I will say min I want to find dominium elements I would say min of the collection with the least which is numbs and if I say enter you can see we got 12 toys the minimum value the same thing you can do with Max in max we can pass noms you got 77 and we can also say some find this sum of all the values is 193 right so normally you do you do all those things by yourself right if you are doing programming this is one thing you do by yourselves using some loop and those concepts by Python says hey don't worry I have some methods for you in fact I forgot to mention one more thing in nums we have below weather which is called a sort so when you say sort and if I syndromes you can see we got all the values in sorted format so yes list is amazing it provides so many features right so that's about least we have so now we know we can have multiple values and least and that they those those things can be of different format and if you want to access any of this element you have to use index values it's mutable so you can change the values you can add values you can remove values and you can you can use certain metals like extend sword to do or to do exciting things and that's it that's about list I hope you are enjoying this series let me know in the comments section and if you're liking this video click on the thumbs up button there and thanks for watching everyone bye you