Function of List
Function of List
sort(): The sort() method is a built-in Python method that, by default, sorts
the list in ascending order. However, you’ll modify the order from
ascending to descending by specifying the sorting criteria.
Eg.
List=[111,112,114,121,122,124,118,119]
List.sort()
type(list): For the type() function, it returns the class type of an object
Eg.
List=[111,112,114,121,122,124,118,119]
type(List)
Eg.
List=[111,112,114,121,122,124,118,119]
List.append([456,345,9809])
Output-[111, 112, 114, 121, 122, 124, 118, 119, [456, 345, 9809]]
extend(): The extend() method increases the length of the list by the
number of elements that are provided to the strategy, so if you’d prefer
to add multiple elements to the list, you will be able to use this method.
Eg.
FUNCTION OF LIST
List=[111,112,114,121,122,124,118,119]
List.extend([453,333,333,478])
print(List)
output-[111, 112, 114, 121, 122, 124, 118, 119, 453, 333, 333, 478]
Eg.
List=[111,112,114,121,122,124,118,119]
List.index(114)
max(list): The max() function will return the highest value of the inputted
values
Eg.
List=[111,112,114,121,122,124,118,119]
max_list=max(List)
print(max_list)
output-124
min(list): The min() function will return the lowest value of the inputted
values.
Eg.
List=[111,112,114,121,122,124,118,119]
min_list=min(List
print(min_list)
output-111
FUNCTION OF LIST
len(list): The len() function shows the number of elements in a list.
Eg.
List=[111,112,114,121,122,124,118,119]
List2=[111,112,114,121,122,124,118,119,56,90,24]
print(len(List))
print(len(List2))
output-
11
List=[111,112,114,121,122,124,118,119]
Eg.
List.clear()
print(List)
output-[]
Eg.
List=[111,112,114,121,122,124,118,119]
List.insert(5,[45,67,89])
print(List)
output-[111, 112, 114, 121, 122, [45, 67, 89], 124, 118, 119]
Eg.
FUNCTION OF LIST
List=[111,112,114,121,122,124,118,119,119,111]
v=List.count(111)
print(v)
output-2
Eg.
List=[111,112,114,121,122,124,118,119,119,111]
List.pop(1)
print(List)
output-
Eg.
List=[111,112,114,121,122,124,118,119,119,111]
List.remove(111)
print(List)
Eg.
List=[111,112,114,121,122,124,118,119,119]
List.reverse()
print(List)
List=[111,112,114,121,122,124,118,119,119,111]
list2=List.copy()
print(list2)
output-[111, 112, 114, 121, 122, 124, 118, 119, 119, 111]