

Print('Updated temperature list: ', temperature) output # use while loop to fill temperature list with temperature degrees We will use While loop to append groups of element to list. 5) Adding element to a list with while loop We made empty list numbers and used for loop to append numbers in range from 0 to 9, so for loop in frist working append 0 and check number 2 in range or not, if in range append it and so on until reaching number 9, which add it and for loop stop working. Print('Updated numbers list: ', numbers) output # use for loop to fill numbers list with elements

We will use For loop to append groups of element to list. 4) Adding element to a list with for loop Print('Updated animal list: ', fruit) outputĪs we saw, the green_fruit list has been added as elements not as a list to fruit list.

Here we wil use extend() method to add element of list to another list, we will use the same pravious example to see the difference. Updated fruit list: ]Īs you see when append green_fruit list to fruit list, it goes as a list not two element. Let's see how to add list to a list # fruit list Updated fruit list: Īs you see, 'pineapple' element has been added as last element. Print('Updated fruit list: ', fruit) output Let's look adding element to a list with an example # fruit list The item can be numbers, strings, another list, dictionary etc. The append() method takes a single item and adds it to the end of the list.
