the elements available in the list. In the statement >>> MyList.remove( ) , deletes the element from the list and the print statement shows the remaining elements. 12th Computer Chapter - - >>> MyList.pop( ) >>> print(MyList) [ , 'Kannan', 'Gowrisankar', 'Lenin'] Example In the above code, pop() function is used to delete a particular element using its index value, as soon as the element is deleted, the pop() function shows the element which is deleted. pop() function is used to delete only one element from a list.
Remember that, del statement deletes multiple elements. >>> MyList.clear( ) >>> print(MyList) [ ] Example In the above code, clear() function removes only the elements and retains the list. When you try to print the list which is already cleared, an empty square bracket is displayed without any elements, which means the list is empty. .
. List and range ( ) function The range() is a function used to generate a series of values in Python. Using range() function, you can create list with series of values. The range() function has three arguments.
Syntax of range ( ) function: range (start value, end value, step value) where, • start value – beginning value of series. Zero is the default beginning value. • end value – upper limit of series. Python takes the ending value as upper limit – .
• step value – It is an optional argument, which is used to generate different interval of values. 12th Computer Chapter - - Lists, Tuples, Sets and Dictionary for x in range ( , ): print(x) Output Example : Generating whole numbers upto for x in range ( , , ): print(x) Output Example : Generating first even numbers (i) Creating a list with series of values Using the range() function, you can create a list with series of values. To convert the result of range() function into list, we need one more function called list() . The list() function makes