List Functions
This Python tutorial gives a list of various list functions that can be applied to a list .
List Methods:
List Data Type has different types of methods and some are there:
- Each and every list method is usually represented in the form object.modulename()
- If any iterable has to be converted int list then list() should be useed
list.append()
- list.append(x)
- Appends x to the end of list. x can be a variable or constant interger or any other character as we can have any type of content in the list.
- list.append(x) is similar to a[len(a):]=[x]
list.extend()
- list.extend(iterable)
- Appends the iterable to the end of the list. Where iterable is a list or a range() of values or a string or a tuple .
- list.extend(iterable) is equivalent to a[len(a):]=iterable
list.insert()
- list.insert(i,x)
- In this method i is the index and x is the value to be inserted ,Hence this function inserts x in the list with an index i.
- a[i]=x is equivalent to list.insert(i,x)
list.remove()
- list.remove(x)
- Removes the first element which matches with x.
list.pop([i])
- a.pop()
- Removes the last element in the list
- list.index(x,i)
- Returns the index which is the second instance of the variable x.
list.count()
- list.count(x)
- Counts all the instances of x.
- list.sort()
- arranges the content of the list in ascending order.
list.reverse()
- list.reverse()
- simply reverses the content of the list ie the last element comes to the first and the first to the last.
list.copy()
- list.copy()
- returns a copy of the list.
- Similar to a[:]
Take a list apply all these functions seems to be intresting
Comments
Post a Comment