Python List

Python List are very important topics each element are assigned with the assign number position to index .

List Operator Basic

Python Expression Description example
len([1, 2]) Length 2
['Hello worlds!'] * 2 Repetition ['Hello world!','Hello world!']
[1,2] + [3,4] Concatenation [1,2,3,4 ]
2 in [1,2] Membership true
for a in [1, 2 ]: print a, Iteration 1 2

Python collition are four type such as List,Tuple ,Tuple ,Tuple

In this chapter we read about List

python List

#first example
list1 = ["php", "sql", "php 7.2.5", "sql"]
Result Answer : ['php', 'sql', 'php 7.2.5', 'sql'] #second example

Change the second item


thislist = ["php 7.2.5 ", "sql", "php"]
thislist[1] = "python"
Try it yourself »

python list() Constructor

list() constructor to make a list


 thislist = list(("Vegetables", "Fruit", "Grain")) # note the double round-brackets
Try it yourself »

Delete List Elements

remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know.


The remove() method removes the specified item:
thislist = ["php 7.2.5 ", "sql", "php"]
Run Example ยป
Sr.No. Methods with Description
1 list.append(obj)

Appends object obj to list

2 list.count(obj)

Returns count of how many times obj occurs in list

3 list.extend(seq)

Appends the contents of seq to list

4 list.index(obj)

Returns the lowest index in list that obj appears

5 list.insert(index, obj)

Inserts object obj into list at offset index

6 list.pop(obj=list[-1])

Removes and returns last object or obj from list

7 list.remove(obj)

Removes object obj from list

8 list.reverse()

Reverses objects of list in place

9 list.sort([func])

Sorts objects of list, use compare func if given