Tuple
A Tuple is a collection of Python objects separated by commas A Tuple is a collection of Python objects separated by commas. In some ways a tuple is similar to a list in terms of indexing, nested objects and repetition but a tuple is immutable unlike lists which are mutable. Tuple
Creating tuple Tuple can be created by using (), Example: Tuple Name=("a", "b") From now we will using t for tuple name Or using tuple constructor, Example: t=tuple(("a", "b")) Note the double round brackets First is for tuple function and second is a iterable having elements to add in the list. Creating tuple
Tuple uses indexing to store elements so we can access items using indexes, Example: t[Index Number] This will return element on that index. We can print this and can also take it into a variable. Can also access all elements using for loop, Example: for i in t: print(i) Accessing tuple
Tuple functions Method Description count() Returns the number of times a specified value occurs in a tuple index() Searches the tuple for a specified value and returns the position of where it was found Tuple functions
Made by Tanmay mudgal