DAY 16 (CODE INFINITY)

Today's topic is tuples, they are collection  of data items and they store multiples items in single variable . Tuples are separated by commas and enclosed with round brackets (). They are unchangeable means we cannot alter them after creation.

Tuple indexes: Each item or element has its own unique index same as we done in lists, range ,positive ,negative indexing is also same as we done in lists. Let's write code for this which make things clear in mind.

tup=(1,2,3,4,5,6,7,8,9,10)

print("the type of tup is",type(tup))

print(tup)

print(tup[0])

print(tup[1])

print(tup[2])

print(tup[3])

print(tup[4])

print(tup[-6])

print(tup[-5])

if 10 in tup:

  print("yes 10 is present in tup")

print(tup[5:9])

print(tup[:])

print(tup[-8:-2])

print(tup[-8:-2:2])

Screenshot which shows how it goes:


Link of the repel:

https://replit.com/@shwetaantil97/-Introduction-to-Tuples



Comments

Lusia said…
Exactly brilliant content made very happy ❤️ with full of knowledge 👍

Popular posts from this blog