Comprehensive notes Tuple functions and methods Class 11

If you are looking for notes Tuple functions and methods Class 11 you are landed on the right page. Here we are going to discuss Comprehensive notes Tuple functions and methods Class 11. Before starting if you missed the articles how to create tuples and QnA creating tuples follow the below given links:

Recommended – Tuple Creation and Traversal

Suggested – QnA Tuple Creation and Traversal

Now let’s start the article Comprehensive notes Tuple functions and methods Class 11. Here we go!

Comprehensive notes Tuple functions and methods Class 11

As we already covered list methods, similarly we tuple functions and methods. These functions and methods are one of the topics of Class 11 curriculum. So in this article we discuss some standard library methods or functions, and tuple methods and function used to manipulate the tuples in Comprehensive notes Tuple functions and methods Class 11.

Standard Library Methods

In this category for Comprehensive notes Tuple functions and methods Class 11, we will discuss abut following standard library methods.

  1. len()
  2. max()
  3. min()
  4. sum()
  5. sorted()

len() function

This function returns the length of a tuple. The length of tuple means total number of elements present in the list.

For example,

t = (22,44,56,78)
print("The tuple contains",len(t), " elements")

max() function

The max function returns the maximum value from the specified tuple.

t=(1,3,5,7,8,4,2)
print(max(t))

In string it will return the highest ordered letter as maximum.

t=('c','b','a','x','u','t')
print(max(t)

This function will only work with tuples having similar data type only. If multiple datatypes combined in the single tuple and you want to print the max() value this function won’t work.

min() function

It will returns minimum value from the sequence specified in the tuple.

t=(34,56,78,21,33)
print(min(t))

Rest min() will work as max().

sum() function

It will return the sum of values used in the tuple sequence.

t=(34,56,789,99)
print(sum(t))

This function only works with numeric elements.

sorted() function

It will returns the tuple elements in ascending or descending order in form of list.

t=(7,3,4,1,2)
print(sorted(t))

For descending order use reverse=True as another parameter. Have a look at this code:

t=(7,3,4,1,2)
print(sorted(t, reverse=True))

Tuple Methods or Functions

In this category we are using methods or function with dot symbol. These methods or functions are as following:

  1. tuple()
  2. index()
  3. count()

tuple() function

As we have seen in the tuple creation, this function convert any sequence of lists into tuple.

index() function

It will return the index of specified tuple element value.

t=(2,5,6,7,8)
print(t.index(6))

The output of above code is 2.

count() function

This function will display number of frequency of elements available in the tuple.

t=(2,3,4,2,3,4,6,7,8,2)
print(t.count(2))

Above code will return 3 as output as 2 is repeated 3 times in the tuple.

Linear search in the tuple

To search in tuple, follow these steps:

  1. Start with the leftmost element in the tuple
  2. Take one variable to flag the message element found on 1
  3. Take a variable to search an element
  4. Traverse the tuple using for loop
  5. Compare the element with the search element
  6. Update the flag variable to 1
  7. Outside the loop, print a message element found or not, using if for the flag variable
def search():
    t = (3,4,1,5,6,8)
    f=0
    n = int(input("Enter the value to search:"))
    for i in range(len(t)): 
        if t[i] == n: 
            f=1
    if f==1:
        print("Found")
    else:
        print("Not Found")

Mean of values stored in the tuple

To find the mean of values in tuple, follow the below given steps:

  1. Import a package statistics
  2. Define the tuple with the values
  3. Declare a variable to store the mean of tuple values
  4. The mean can be displayed with float value so use round function to restrict its decimal places
  5. Use print to print the final value

Observe the following code:

import statistics 
t = (1, 3, 4, 5, 7, 9, 2 )
meanoftuple = round(statistics.mean(t) ,2)
print("Mean is :", meanoftuple) 

That’s all from the topic Tuple functions and methods Class 11. I hope that all the concepts are clear to you. If any specific doubt or query you have, you are free to ask through the comment section.

Share your views on this article as your token of love and support.

Thank you very much for reading this article.

If you are looking for more contents for Class 11, follow the below given link:

Recommended – Computer Science Class 11

Leave a Reply