You are on page 1of 5

##introduction to list and tuple##

#d\f b\w tuple and list

#TUPLE

a=(4,6,34,2,3,5)

print(a[1])

#tuple can't be changed

#a=(4,6,34,2,3,5)

#a[2]=45

#print(a)

#[error]

#list

a=[4,6,34,2,3,5]

print(a[1])

print(a[0:2])
#list can be change

a=[21,7,5,9]

a[3]=45

print(a)

print(a[0:2])

#tuple.method
#t.count()

#t.count()

#t.count(it calculate the specific numbers in tuple)

a=(1,3,5,7,0,9,0)

print(a.count(0))

#it gave index value

a=(1,3,5,7,0,9,0)

print(a.index(0))
#list slicing
#l.sort (it arrange the list)

#l.reverse() (it reverse the list)

#l.append() (it add (bracket) value in the end of the list)

#l.insert(index,word) (it insert value on given index)

#l.pop(index) (it remove index value)

#l.remove() (it removr bracket value in list)

list=[1,2,5,8,4,98,0]

list.sort()

print(list)

list=[1,2,5,8,4,98,0]

list.reverse()

print(list)

list=[1,2,5,8,4,98,0]

list.append(6)

print(list)

list=[1,2,5,8,4,98,0]

list.insert(2,55)
print(list)

list=[1,2,5,8,4,98,0]

list.pop(0)

print(list)

list=[1,2,5,8,4,98,0]

list.remove(8)

print(list)

#write a program tp store 7 fruits in list which is entered by the user

a=input("enter fruit ")

b=input("enter fruit ")

c=input("enter fruit ")

d=input("enter fruit ")

e=input("enter fruit ")

f=input("enter fruit ")

g=input("enter fruit ")

myfruitlist=[a,b,c,d,e,f,g]

print(myfruitlist)
#write a program that accept 6 student marks and sort it

a=input("enter marks 1 ")

b=input("enter marks 2 ")

c=input("enter marks 3 ")

d=input("enter marks 4 ")

e=input("enter marks 5 ")

f=input("enter marks 6 ")

stdmarkslist=[a,b,c,d,e,f]

stdmarkslist.sort()

print(stdmarkslist)

#write a program to sum a list with 4 num

l1=[2,3,5,2]

print(l1[0]+l1[1]+l1[2]+l1[3])

#wrie a program to count 0 in following tuple

a=(93,0,5,0,3,0,4,0,40,0,43,0,3,0,3,0,3,0,340,0)

print(a.count(0))

You might also like