Python Lab Manual Answers (22616) Practical 7

 Python Lab Manual Answers (22616) 

Practical 7 :  Write Python program to perform following operations on Tuples: Create Tuple, Access Tuple, Update Tuple, Delete Tuple


* Practical Related Question.
1) Define empty tuple. Write syntax to create empty tuple.
Ans=> 1)Tuples are used to store multiple items in a single variable.
            2)A tuple is a collection which is ordered and unchangeable.
            3) A Tuple with no single item is called empty tuple 
            4)We can create an empty tuple in Python in two ways. The first one providing no elements in the parenthesis, and the second is providing no iterable to the tuple() builtin function.
          5)Syntax : 


tuple1=()


2) Write syntax to copy specific elements existing tuple into new tuple.
Ans=>
t1 = (1, 2, 3, 4, 5)
newt1 = t1
t1[0] = 5
newt1t1


3)Compare tuple with list 
Ans=>
                    List                                      Tuple
            List are Mutable                  Tuple are Unmutable  
 
           List Consume                       Tuple Consume 
          More Memory                         less memory     

          List Have                              Tuples have
         many methods                        less methods
 
         List enclosed in                      Tuple Enclosed in 
          square bracket                       parenthesis 


*Exerecise 

1. Create a tuple and find the minimum and maximum number from it.
Ans=>


tup=('vaishnavi', 'msbte', 'sppu')
print("Maximum value : ",max(tup))
print("Minimun value : ",min(tup))


2. Write a Python program to find the repeated items of a tuple.
Ans=>

numbers=(1,2,4,7,1,4)
print(numbers)
count=numbers.count(1)
print(count)



3. Print the number in words for Example: 1234 => One Two Three Four
Ans=>

array = ['zero','one','two','three','four','five','six','seven','eight']
num=input("Enter a number : ")
print(num)
word=[]
for a in num:
    word.append(array[int(a)])
print(word)





*Practical Outcome(PrOs)
Write Python program to perform following operations on Tuples:
1. Create Tuple
2. Access Tuple
3. Update Tuple
4. Delete Tuple
.
.
.
.
keep Growing ......

Post a Comment

0 Comments