List Operation in Python:-



LIST provides a mutable object that means we can add, edit, and delete elements dynamically in the list.

x = [12,23]
Add element:-
x.append(24)   #[12,23,24]

Delete an element from LIST

del  x[0]

Modify List element:-

x[index]=value

all arithmetic operation

a= [1,2,3]
b = [4,5,6]

c=a+b

[1,2,3,4,5,6]

a*2


Program of LIST:-

a=[1,2,3]
b=a*2
print(b)
x=[1,2,3]
y=[4,5,6]
z=x+y
print(z)
del x[0];
print(x)

if(20 in a):
    print("Found")
else:
    print("NOT found")

y=x
print(x)
print(y)
if(x is y):  #if same address then return true otherwise
    print("equall")
else:
    print("not equall")
    



....................................................................................................

Multidimensional LIST:-

x = [[1,2,3],[4,5,6]]
for i in range(0,2):
    for j in range(0,3):
        print(x[i][j],end=' ')
    print()   










Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post