List Manipulation
List Manipulation
List Creation
• List is a standard data type of Python. It is a sequence which
can store values of any kind.
• List is represented by square brackets “ [ ] “
For ex -
o [ ] Empty list
o [1, 2, 3] integers list
o [1, 2.5, 5.6, 9] numbers list (integer and float)
o [ ‘a’, ‘b’, ‘c’] characters list
o [‘a’, 1, ‘b’, 3.5, ‘zero’] mixed values list
o [‘one’, ’two’, ’three’] string list
• In Python, only list and dictionary are mutable data types, rest
of all the data types are immutable data types.
Creation of List
• List can be created in following ways-
• Empty list –
• Long lists-
• Nested list -
Accessing a List
• First we will see the similarities between a List and a String:
o List is a sequence like a string.
o List also has index of each of its element.
o Like string, list also has 2 index, one for forward
indexing (from 0, 1, 2, 3, ….to n-1) and one for
backward indexing(from -n to -1).
• In a list, values can be accessed like string.
• Len() Function is used to get the length of list.
List Slicing
• To slice a List, syntax is:-
• List.index() function:
• List.append() function:
• List.extend() function:
• List.insert() function:
• List.pop() function:
• List.remove() function:
• List.clear() function:
• List.count() function:
• List.reverse() function:
• List.sort() function: