Page 139 - Code_GPT_Class_8
P. 139
Program 10: To use the built-in Python list functions
Program10.py
File Edit Format Run Options Window Help
list1=[13, 25, 41, 63, 82] Output
print(len(list1))
5
print(max(list1))
82
print(min(list1))
13
OPERATIONS ON A LIST
There are several operations which can be performed on the list. The following table describes the
various list operations:
Operator Operations Explanation
+ Joining lists To add/concatenate two lists together by using the ‘+’ operator
It multiplies a list by an integer ‘n’ and then creates a new list which repeats the
* Repeating lists
original list ‘n’ times by using the ‘*’ operator
: Slicing lists To access the list elements within a specific range
== Comparing list To check if the contents of the list are the same or not by using the ‘==’ operator
Program 11: To perform the operations on the list
Program11.py
File Edit Format Run Options Window Help
list1=[13, 25, 41, 63, 82]
list2=[23, 35, 51, 73, 92]
print(list1+list2)
print(list1*4)
print(list1[0:4])
print(list1==list2)
On running the above program, you will get the following output:
Output
[13, 25, 41, 63, 82, 23, 35, 51, 73, 92]
[13, 25, 41, 63, 82, 13, 25, 41, 63, 82, 13, 25, 41, 63, 82, 13, 25, 41, 63, 82]
[13, 25, 41, 63]
False
List in Python 137

