LIST METHODS AND OPERATIONS

GOCOURSE



List Methods And Operations:

Working with a list is made easier by the built-in methods that Python provides. The dot operator is used to access list methods.


Syntax: 

Listname.method()

method() Description
append() used to add element at the end of the list
clear() Removes all the element in the list
copy() Returns copy of the list
extend() Adds element at the end of the list
insert() Adds element at the specified index of the list
pop() Remove element at the specified index
remove() Remove the item with specified value
reverse() Reverse the order of the list
sort() Sort the list


Program 1:


mylist=['bike','car']

  mylist.append('bus')

print(mylist)


Output:


['bike', 'car', 'bus']


Program 2:


mylist=['bike','car','bus']

mylist.pop(2)

print(mylist)



Output:


['bike', 'car']







More topic in Python

Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send