Tuples in Python

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

#Program for Tuple Data type (Collection)

#mytuple1=(10,20,30,40,50,60,70)
# for x in mytuple1:
#  print(x)
# for i in range(0,len(mytuple1),1):
#     print(mytuple1[i])
# i=0
# while(i<len(mytuple1)):
#      print(mytuple1[i])
#      i+=1
#mytuple1[4]=600  # Error
#print(mytuple1[4])
#print(mytuple1[2:5])
#print(mytuple1[9])
# print(mytuple1)
# mytuple2=(101,"Vivek",98.44,True,"Vivek",101)
# print(mytuple2)

# a=(10,)
# print(type(a))
# b=(20)
# print(type(b))
# c=(a+b)
# print(c)
# mylist=10,20,30,40
# mytuple=10,20,30,40
# print(type(mylist))
# print(type(mytuple))

# myt=10,
# print(type(myt))
# mytuple=(10,20,30,40,50,60,90,20,30,20)
# #print(mytuple.count(20))
# print(mytuple.index(20))

# How to Add Run time elements
mylist=[]
n=int(input("Enter the limit"))
print("Enter elements in Tuple: ")
for i in range(0,n,1):
    x=int(input())
    mylist.append(x)
mytuple=(mylist)  # Covert list into tuple
print("Elements of Tuple: ")
print(mytuple)

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *