exp 6
exp 6
1
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
THEORY:
There are different types of data types in python like Tuple, Set, Dictionary, etc. The one that is
both changeable and ordered is called List in Python. It also allows duplicate values as a
member, wherein each member can be accessed separately in an iterative fashion. In this topic,
we are going to learn about Python List Functions.
print(List)
Output:
2
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
1. In Operator
It is utilized to verify whether any specific element is a member of the list or not.
Code:
lst = [1 , 6 , 7 , 4 , 3]
if 1 in lst:
3
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
Output:
2. Not In Operator
It is utilized to verify whether any specific element is not a member of the list.
Code:
lst = [1 , 6 , 7 , 4 , 3]
if 1 not in lst:
Output:
4
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
len(): This function returns the length of the list passed as an argument.
min(): This function returns the minimum element of the list passed as an
argument.
max(): This function returns the maximum element of the list passed as an
argument.
Code:
# Python code to showcase the usage of len(), max() & min() function
lst = [1 , 6 , 7 , 4 , 3]
print(len(lst))
5
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
print(min(lst))
print(max(lst))
Output:
3. + Operator
This operator is utilized to append the members of two lists together in a single one.
Code:
# creating list 1
6
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
# creating list 2
print(lst3)
Output:
4. * Operator
This operator is utilized to repeat the members of the list the times the operator is used
with * operator.
Code:
7
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
# creating list 1
lst3= lst * 2
print(lst3)
Output:
8
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
count(): This function returns the number of times an element is present in the
list
Code:
# creating list 1
print(lst.count(37))
Output:
9
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
Code:
# creating list 1
lst.remove(37)
print(lst)
Output:
10
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
Here if we notice carefully, the very first occurrence of 37 is removed from the list
sort(): This python function is utilized to sort the list passed as an argument in
ascending order.
Code:
# creating list 1
lst.sort()
print(lst)
Output:
11
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
Code:
# creating list 1
lst.reverse()
print(lst)
Output:
12
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
clear(): This function is utilized to empty the list passed as an argument to this
function.
Code:
# creating list 1
lst.clear()
print(lst)
13
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
14
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering
Conclusion.
15