

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of various operations that can be performed on lists in Python. It covers topics such as creating a list, user input list, indexing of list, creation of multi-dimensional list, different operators with list, and list functions. code snippets and examples to illustrate each topic. useful for students learning Python programming and looking to understand the basics of list operations in Python.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


list1 = []; list2 = list(); #Creation of empty list print("enter elements enter # when done") entry=input("element no 1 = ") list1.append(entry) i= 2 while(entry!='#'): entry = input(f"element no {i} = ") i+= 1 list1.insert(i- 1 ,entry) if(entry=="#"): list1.pop() print(f" you have entered {i- 2 } elements") print(list1) print(len(list1)) print(list1[ 0 ]) print(list1[- 1 ])
#multi-dimensional list list3 = []
n= 5 ;r= 5 ;c= 6 ;list3=[];k= 1 for i in range(r): i=[] for j in range( 1 ,c+ 1 ): i.append(k) k+= 1 list3.append(i) for i in range(len(list3)):
for j in list3[i]: print(j,end=' ') print()
l1 = [ 1 , 2 , 3 ,"alok"] l2 = [ 21 , 32 , 43 ,"alka"] #arithmetic print(l1+l2) print(l2* 3 ) #relational print(l1>l2);print(l1=l2);print( l1<=l2) #membership operator print( 2 in l1) print( 23 not in l1) #identity operator print(l2[ 0 ] is 21 ) #slicing print(l2[::- 1 ])