{"id":24823,"date":"2021-11-02T09:54:18","date_gmt":"2021-11-02T04:24:18","guid":{"rendered":"https:\/\/python-programs.com\/?p=24823"},"modified":"2021-11-05T20:37:52","modified_gmt":"2021-11-05T15:07:52","slug":"python-max-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-max-function-with-examples\/","title":{"rendered":"Python max() Function with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python len() Function with Examples<\/a>
\nmax() Function in Python:<\/strong><\/p>\n

The max() function returns the item with the highest value or the highest value in an iterable.<\/p>\n

If the values are strings, they are compared alphabetically.<\/p>\n

Syntax:<\/strong><\/p>\n

max(iterable)<\/pre>\n

or<\/p>\n

max(n1, n2, n3,........)<\/pre>\n

Parameters<\/strong><\/p>\n

iterable:<\/strong> An iterable that compares one or more items.<\/p>\n

n1, n2, n3,……..<\/strong>: a single or multiple items to compare.<\/p>\n

Return Value:<\/strong><\/p>\n

max() returns the iterable’s largest element.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [1, 2, 5, 6, 15, 7]<\/pre>\n

Output:<\/strong><\/p>\n

The greatest number in the given list = 15<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [\"hello\", \"this\", \"is\", \"btechgeeks\"]<\/pre>\n

Output:<\/strong><\/p>\n

The largest string in the given list (alphabetically ordered) is :\r\nthis<\/pre>\n

Note:<\/strong><\/p>\n

If the items in an iterable are strings, the largest (alphabetically ordered) \r\nitem is returned.<\/pre>\n

max() Function with Examples in Python<\/h2>\n