Python 3 – Tuple min() Method
In Python 3, the min() method is used to get the minimum value from a tuple. It is a built-in method that takes a tuple as an argument and returns the minimum value from the tuple.
Syntax
min(tuple)
The min() method takes a tuple as an argument and returns the minimum value from the tuple.
Parameters
- tuple – Required. The tuple from which to retrieve the minimum value.
Return Value
The min() method returns the minimum value from the tuple passed as an argument.
Example
# Example 1
# Get the minimum value from a tuple
my_tuple = (3, 4, 5, 1, 2, 9)
print("Minimum value of my_tuple is : ", min(my_tuple))
Output:
Minimum value of my_tuple is : 1
# Example 2
# Get the minimum value from a tuple of strings
my_tuple = ('cat', 'dog', 'elephant', 'horse')
print("Minimum value of my_tuple is : ", min(my_tuple))
Output:
Minimum value of my_tuple is : cat
Explanation
In example 1, the min() method is used to get the minimum value from a tuple of integers. We have defined a tuple my_tuple
and passed it as an argument to the min() method. The minimum value from the tuple is returned by the min() method.
In example 2, the min() method is used to get the minimum value from a tuple of strings. We have defined a tuple my_tuple
and passed it as an argument to the min() method. The minimum value from the tuple is returned by the min() method.
Conclusion
In conclusion, the min() method is a useful built-in method that is used to get the minimum value from a tuple in Python 3. This method takes a tuple as an argument and returns the minimum value from the tuple. It can be used with tuples of integers and strings, and the returned value will be the minimum value from the tuple.