The Wayback Machine - https://web.archive.org/web/20240118175249/https://www.geeksforgeeks.org/python-tuple-max-method/
Open In App
Related Articles

Python Tuple – max() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

While working with tuples many times we need to find the maximum element in the tuple, and for this, we can also use max(). In this article, we will learn about the max() method used for tuples in Python.

Example

Tuple =( 4, 2, 5, 6, 7, 5)

Input:

max(Tuple)

Output: 7

Explanation: The max() method returns the largest element of the given tuple.

Python tuple max() Method

Syntax: max(object)

Parameters:

  • object: Any iterable like Tuple, List, etc.

Return type: maximum element from the tuple.

Example 1: Using tuple max() Method

Here we are finding the max of a particular tuple.

Python3




# Creating tuples
Tuple = ( 1, 3, 4, 2, 5, 6 )
   
res = max(Tuple)
print('Maximum of Tuple is', res)


Output:

Maximum of Tuple is 6

Example 2: Using tuple max() Method for string elements

Here we are finding the maximum element out of the tuple that constitutes string elements based on length.

Python3




# Creating tuples
Tuple = ( "Geeks", "For", "Geeks", "GeeksForGeeks")
  
res = max(Tuple)
print('Maximum of Tuple is', res)


Output:

Maximum of Tuple is GeeksForGeeks

Example 3: Using max for equal-length elements

Here we are finding the maximum element among the tuple of equal length elements. Where it gives the lexicographically largest string.

Python3




# alphabets tuple
alphabets = ('GFG', 'gfg', 'gFg', 'GfG', 'Gfg')
  
res = max(alphabets)
print('Maximum of Tuple is', res)


Output:

Maximum of Tuple is gfg

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 07 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials