DAY 17(CODE INFINITY)

Today we continue our previous topic tuples in this we study today operations in tuples as we all know tuples are immutable , if you want to add, remove or change tuple items, then first you must convert the tuple to a list. Then perform operation on that list and convert it back to tuple.

We convert the tuples to a list, manipulate items of the list using list methods, then convert list back to a tuple and we can directly concatenate two tuples without converting them to list.

Tuple Methods:

1. count(): This method returns the number of times the given element appears in the tuple.

2. index(): This returns the first occurrence of the given element from the tuple 

Let me give you an example of how this works:

tup=("Shweta","Anjali","Mohit","papa","mummy","sadness")

abc=tup.count("Shweta")

print(abc)

abc=tup.index("Mohit")

print(abc)

abc=tup.remove("all")

print(abc)

Screenshot of repel:

Link of the repel:

https://replit.com/@shwetaantil97/-Operations-on-Tuples#main.py 




Comments

Lusia said…
Excellent Code Infinity blog 💯❤️

Popular posts from this blog