Podcast Lookup

_5 Python Tutorial for Beginners _ List in Python

Python To You

  • October 10, 2026
  • 11 min
Episode page

About this episode

No description.

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

_5 Python Tutorial for Beginners _ List in Python

00:00—
  1. Speaker 1

    Welcome back aliens. My name is Daivin Reddy 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 worked with variables. In this video, we'll work with a concept called as 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 list, right? Now what is list? Now 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 list? It's very simple actually. Let's say I have some nums. Okay, so we have this variable called nums equal to and now we can assign the values. Instead of 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, which is called square brackets. So we have to use square brackets here. And in this square bracket, you have to mention the values. Okay, now which one? Any value doesn't matter. So I will say 25, 12, maybe 36, maybe 95, 14. So I got these values. Now these are the list of values which I have here. Now you might be thinking, can we only have similar type of data? Example, all these things are numbers, right? Let's try that as well. So 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 got 25, 12, 36, 95 and 14. That's so simple. Now, if you remember in the last session, we have also talked about string and we said, OK, string is a 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 say I want to pick up the first value, which is 25 in this case. You know the answer, right? So we simply have to say nums and 0 enter. Oh, it worked. You can see we got 25. Let's say I want to fetch the last value, which is nums of, it should be 5, right? So, oh, 4, because the value, the size of the list is 5. typos doesn't matter so if i say enter you can see we got 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 first and last you can pick up any value right what if you want to print something in between and then till the end Now if you remember in string as also we have done that so example I want to print third element fourth and fifth so third and then to the end so of course we can do that we 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 the third element fourth and fifth. Now, what do you think? Can we use negative numbers the way we have done before? You know, the index number as negative minus one, minus two, minus three. Yes, it works here as well. So we can say nums of. So if you want to pick up that 14, which is at the end, you're right. We have to use minus one and it works. If you want to fetch the first element, we have to say minus five. 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 array here or another list here? We'll say nums, we'll say names and names of. So, what names? So, I can have any names here, right? I can have Naveen, I can have Kiran and I can have, let's say, John. So, we got these three names here, right? And the moment I say enter, you can see we also have a list of string and if I print names you got the names there okay so now if you can see one array which is numbers we have second array which is names which is of string we can create different list of different types now can I create a list of different types I mean one list of different types I will simply call it as values equal to and I want to have any type of value here example the first one I would say is 9.5 which is a float value then I want to go for a string I will go with my name And then let's say another one, which is 25, which is a number, right? So we have a float number. We have a string and an integer number. If I say enter, it works. Okay, so we can have a list with different type of data. And that's the beauty about list, you know, you can have different data. 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 array, but okay, let's not discuss that here. If you're 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? I mean, something like this. I want to get another list here. Mill is equal to miscellaneous things. So I will say mill is equal to I want to have a list of list. Can we do that? Let's try. So I want to have this list which will have nums and which will also have names. So a mill will have names and nums and names. Enter. There is no error. Okay. I will say mill. Okay. You can see we got 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 say nums dot. The moment you say nums dot, of course, we have not got. Oh, we got the pop up there. Can you see that? Now you can see we got append. 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. Oh, what is that? Mutable simply means you can change the values and we can do that here nums.append I want to append what I want to append let's say I want to append 45 and now if I say nums 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 clear as well so clear will clear the entire list for you try it out you know once you are 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 append and insert in append it will append at the end in insert it will add in between let's try so in 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 it's 2077 i will say enter And now if I print nums, 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 nums dot. There's a method called 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 nums 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 even that is simple you just need to use a method of a pop so you have to say nums dot pop inside this pop you just pass the index number which one which I want to delete let's say I want to delete 12 So in this case I will pass 1 and you can see we got 12 out. How do I verify if I say num so you can see we don't have 12 now. Okay in fact we can also use pop without an index value. What happens when you use pop without index value? Now if you have learned 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 the 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 will say enter you can see we got 45 so if you don't specify the index value you got the last element so you can use this when you implement stack in data structures yeah Okay, so we can use remove, 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 again a command. And then you have to pass the name of the list, which is nums. And in the area, you have to specify the index value from where you have to start. I want to start from, let's say, two. And then I want to end it. I want to delete all the remaining elements, you know, so I will say enter. And if I verify now, you can see we got only two values, the 0th and 1st, because from 2 everything is deleted. So that's how you can work with nums. Now, let me just add some values there. Oh, how to 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 extend. Again, you need to read documentation for this. So there's one question from everyone, you know, from where to learn, from where to read. Of course, you're watching this video, but reading is also important, right? What if I say Python has this amazing documentation online? So you 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.extend and in the bracket, specify multiple values if you want. Example, I want to add 29, 12 again, 14, 36. I want to add these four values. Simply say enter. We have done a mistake. Okay, I guess we have to give a square bracket as well. Oh, so that was a mistake. We have to put that value in square bracket. My bad. And if I say nums, you can see we got the value. So, we got a least now. Now, with this least, we can perform some inbuilt functions. You know, in Python, we have these inbuilt functions. Now, how do I know which inbuilt function we have? We have min, we have max. we can find some, so we have those methods here, so let's try, so can we use inbuilt functions, let's try, so I will say min, I want to find the minimum element, so I will say min of the collection of deletes which is nums and if I say enter you can see we got 12, 12 is the minimum value. The same thing you can do with max. In max you can pass nums. You got 77 and we can also say sum. Find the sum of all the values and it's 193, right? So normally you do all those things by yourself, right? If you are doing programming. This is one thing you have to do by yourself using some loop and those concepts. But 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 one more thing which is called a sort. So when you say sort, and if I say nums, 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 it. we have. So now we know we can have multiple values and list and that 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 use certain methods like extend sort to do exciting things. And that's it. That's about list. I hope you're enjoying this series. Let me know in the comment section. And if you're liking this video, click on the thumbs up button there. And thank you so much for watching, everyone. Bye-bye.