Adding items into a List

Adding items into a List

Lesson Details:
September 17, 2020

Video Transcription: In this lecture we are going to learn how to add and append new items in a list this video is brought to you by Appy Pie’s Academy, it's very easy to do it but let me start with the list with the name values I have assigned it the values 100 200 and 1000 and I'm going to write values dot append and 2500 append is something that means that the value will be added only in the end of the list so when I will print values the output is going to be one hundred two hundred one thousand and twenty five hundred right a panda is just inserting at the end of the list so append is the function when I would write values dot append 2500 it will be appended in the last so in order to prove this I am going to print the list values and I have written the alternative syntax also go to run and then after run you will see the output yeah you can see 100 200 1000 and this is the new value that was appended in the last by using the append function okay let's move forward now you can also list into another list what I want to say is you can also add a list you write values dot extend extend is a function what it will do is it will add a list into another list the list already existing list is values when I would write values dot extend values dot extend and then I am writing 91 zero one seven eight nine this is the list that will be that will be extended with this values list so you can let me change the comment you can also add a list into another list using extend function so missus head this is the list that will be added into already existing list values I will print values and I will see the output okay click on run yeah that's it hundred two hundred one thousand this was these were the values of the list values and ninety one zero one seven eight nine this was the list which was up added into it okay let's proceed further I'm going to take another list with the name number so I'm giving the number 10 comma twenty five let it become my tea or something nine zero nine okay now what I am going to do is I'm going to write print and then values which is the name of the list then I would write values plus number right it's very simple to understand it the values and numbers both the both the both the lists they will be merged together so you can see it right so the value is being displayed on under two hundred one thousand for a five hundred ninety one zero one seven eight nine and ten twenty five eighty nine zero nine so what you can see is the values list was containing the values till seven eight nine and ten twenty five eighty nine zero nine which came from the list number they were appended by using the concatenation symbol plus now we will discuss another very interesting operator multi which can be used in the context of lace we can use multiplication symbol to repeat a value so what I will do is suppose I am going to write print and then within square brackets a nun okay multiplied by five right so this Arnon is a list what will happen is our ninth value will be repeated five times a nun value of this list will be repeated five times this is an unnamed list yeah you can see anant is being displayed five times.

loader
Course content