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:
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.
This function returns the length of a tuple. The length of tuple means total number of elements present in the list.
t = (22,44,56,78) print("The tuple contains",len(t), " elements")
The max function returns the maximum value from the specified tuple.
In string it will return the highest ordered letter as maximum.
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.
It will returns minimum value from the sequence specified in the tuple.
Rest min() will work as max().
It will return the sum of values used in the tuple sequence.
This function only works with numeric elements.
It will returns the tuple elements in ascending or descending order in form of list.
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:
As we have seen in the tuple creation, this function convert any sequence of lists into tuple.
It will return the index of specified tuple element value.
The output of above code is 2.
This function will display number of frequency of elements available in the tuple.
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:
- Start with the leftmost element in the tuple
- Take one variable to flag the message element found on 1
- Take a variable to search an element
- Traverse the tuple using for loop
- Compare the element with the search element
- Update the flag variable to 1
- 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:
- Import a package statistics
- Define the tuple with the values
- Declare a variable to store the mean of tuple values
- The mean can be displayed with float value so use round function to restrict its decimal places
- 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: