Describe list() with its syntax.
Answers
Answered by
1
Answer:
List Methods in Python | Set 2 (del, remove(), sort(), insert(), pop(), extend()…) append(): Used for appending and adding elements to List.It is used to add elements to the last position of List. # Adds List Element as value of List. insert(): Inserts an elements at specified position
Answered by
1
List, in python, is a data structure which is ordered, mutable, and allows non-homogenous element type.
Describe list() with its syntax.
- List can look like:
- [ ] - empty list
- [ 1, 2, 3 ] - list with element type integer
- [ 'a', 'b', '1' ] - list with element type string ( '1' is treated as string in python)
- [ 'a', 1, [1,2,3] ] - list with mixed element type
- There are various function which can be applied on list. e.g.
- append() Adds an element at the end of the list
- clear() Removes all the elements from the list
- copy() Returns a copy of the list
- count() Returns the number of elements with the specified value
- extend() Add the elements of a list (or any iterable)
- index() Returns the index of the first element with the specified value
- insert() Adds an element at the specified position
- pop() Removes the element at the specified position
- remove() Removes the first item with the specified value
- reverse() Reverses the order of the list
- sort() Sorts the list
Similar questions