append(): Used for appending and adding elements to List.It is used to add elements to the last position of List.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
insert(): Inserts an elements at specified position.
Syntax:
python - Sample - python code :
Note: Position mentioned should be within the range of List, as in this case between 0 and 4, elsewise would throw IndexError.
python - Sample - python code :
python programming - Output :
extend(): Adds contents to List2 to the end of List1.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
sum(), count(), index(), min() and max() functions of List
sum() : Calculates sum of all the elements of List.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
What happens if numeric value is not used a parameter?
Sum is calculated only for Numeric values, elsewise throws TypeError.
See example:
python - Sample - python code :
python programming - Output :
count():Calculates total occurrence of given element of List.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
index(): Returns the index of first occurrence. Start and End index are not necessary parameters.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
Another example:
python - Sample - python code :
python programming - Output :
python - Sample - python code :
python - Sample - python code :
min() : Calculates minimum of all the elements of List.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
max(): Calculates maximum of all the elements of List.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
sort() and reverse() functions
reverse(): Sort the given data structure (both tuple and list) in ascending order. Key and reverse_flag are not necessary parameter and reverse_flag is set to False, if nothing is passed through sorted().
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
python - Sample - python code :
python programming - Output :
Deletion of List Elements
To Delete one or more elements, i.e. remove an element, many built in functions can be used, such as pop() & remove() and keywords such as del.
pop(): Index is not a necessary parameter, if not mentioned takes the last index.
Syntax:
python - Sample - python code :
Note: Index must be in range of the List, elsewise IndexErrors occurs.
python - Sample - python code :
python programming - Output :
python - Sample - python code :
python programming - Output :
del() : Element to be deleted is mentioned using list name and index.
Syntax:
python - Sample - python code :
python - Sample - python code :
python programming - Output :
remove(): Element to be deleted is mentioned using list name and element.
Wikitechy tutorial site provides you all the learn python , free python online course , best online course to learn python , learn how
to program in python python
training free
Related Searches to List methods in Python
python find in listpython print listpython empty listlist to string pythonlist functions pythonpython string to listpython list extendpython list countcreate list pythonpython list joinpython list of listspython 3 listpython functions listpython list findreverse list pythonpython list reversepython compare listspython list of dictionariesprint list pythonempty list pythonlist of lists pythonpython count items in listpython list to setpython slice listpython append list to listlist pop pythonlist remove pythonlist in pythonpython concatenate listspython listepython size of listpython list containspython list sizepython list lengthpython initialize listpython length of listliste pythonpython list slicinglength of list pythonpython list poppython remove from listpython list removepython remove item from listpython enumerate listpython commands listremove from list pythonpython delete from listlistas pythonpython for loop listpython map listpython dict to listconcatenate lists pythonpython list() functionpython create empty listpython list index