Python Tuple min() Method



The Python Tuple min() method returns the elements from the tuple with minimum value.

Finding the minimum of two given numbers is one of the usual calculations we perform. In general min is an operation where we find the smallest value among the given values. For example, from the values “10, 20, 75, 93” the minimum value is 10.

Syntax

Following is the syntax of Python Tuple min() method −

min(tuple)

Parameters

  • tuple − This is a tuple from which min valued element has to be returned.

Return Value

This method returns the elements from the tuple with minimum value.

Example

The following example shows the usage of Python Tuple min() method. Here, two tuples 'tuple1' and 'tuple2' are created. The method performs alphabetical comparison on the string elements of the tuple created. Then the smallest element of this tuple is retrieved using min() method.

tuple1, tuple2 = ('xyz', 'zara', 'abc'), (456, 700, 200)
print ("min value element : ", min(tuple1))
print ("min value element : ", min(tuple2))

When we run above program, it produces following result −

min value element :  abc
min value element :  200

Example

Now let us find the minimum number in a tuple containing only numbers in the example below.

# creating a tuple
tup = (465, 578, 253, 957)
res = min(tup)
# printing the result
print("Minimum element is: ", res)

While executing the above code we get the following output −

Minimum element is:  253

Example

In here, we are creating a tuple 'tup'. This tuple contains equal length elements. So, the min() method is used to retrieve the minimum element among the tuple which is lexicographically smallest.

tup = ('DOG', 'Dog', 'dog', 'DoG', 'dOg')
# printing the result
print('Minimum element is: ', min(tup))

Following is an output of the above code −

Minimum element is:  DOG

Example

In this example, let us consider a real-time scenario where this method might come in handy. We are creating two tuples: one containing student names and the other containing their marks in the corresponding index. The lowest marks are found using the min() method and the corresponding index of the student with the lowest marks is retrieved using the index() method. The student bearing the lowest marks has to be announced as the failure.

marks = (768, 982, 876, 640, 724)
student = ('Deependra', 'Shobhit', 'Alka', 'Pawan', 'Sam')
rank_last = min(marks)
name_id = marks.index(min(marks))
print(student[name_id], "ranked last with", rank_last, "marks")

Output of the above code is as follows −

Pawan ranked last with 640 marks
python_tuples.htm
Advertisements