[{"data":1,"prerenderedAt":2225},["ShallowReactive",2],{"doc-\u002Freference\u002Fpython-max-function-explained":3},{"id":4,"title":5,"body":6,"description":2218,"extension":2219,"meta":2220,"navigation":123,"path":2221,"seo":2222,"stem":2223,"__hash__":2224},"content\u002Freference\u002Fpython-max-function-explained.md","Python max() Function Explained",{"type":7,"value":8,"toc":2175},"minimark",[9,19,26,29,39,42,47,214,217,236,239,259,266,271,285,288,291,295,300,418,421,440,447,450,516,518,527,530,544,547,596,598,607,621,627,630,660,662,671,674,677,752,754,763,766,772,777,828,830,838,841,844,862,865,917,920,926,933,939,942,947,1010,1012,1021,1028,1041,1045,1112,1114,1122,1128,1132,1138,1226,1228,1237,1247,1252,1257,1260,1297,1299,1308,1311,1317,1319,1371,1373,1382,1385,1406,1410,1415,1422,1430,1457,1460,1485,1490,1527,1534,1541,1546,1592,1595,1598,1638,1645,1651,1656,1672,1677,1685,1688,1692,1697,1701,1706,1708,1770,1772,1804,1810,1817,1826,1830,1833,1860,1863,1976,1979,1998,2008,2012,2019,2022,2029,2032,2036,2047,2054,2058,2116,2124,2132,2136,2171],[10,11,13,14,18],"h1",{"id":12},"python-max-function-explained","Python ",[15,16,17],"code",{},"max()"," Function Explained",[20,21,22,23,25],"p",{},"The built-in ",[15,24,17],{}," function returns the largest item.",[20,27,28],{},"You can use it in two main ways:",[30,31,32,36],"ul",{},[33,34,35],"li",{},"To get the largest item from an iterable like a list or tuple",[33,37,38],{},"To compare two or more separate values",[20,40,41],{},"This is useful when you want the highest number, the alphabetically largest string, or the biggest item based on a custom rule.",[43,44,46],"h2",{"id":45},"quick-example","Quick example",[48,49,54],"pre",{"className":50,"code":51,"language":52,"meta":53,"style":53},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","numbers = [3, 8, 2, 5]\nprint(max(numbers))\n\nprint(max(3, 8, 2, 5))\n\nwords = [\"apple\", \"banana\", \"pear\"]\nprint(max(words))\n","python","",[15,55,56,96,118,125,152,157,198],{"__ignoreMap":53},[57,58,61,65,69,73,77,80,83,85,88,90,93],"span",{"class":59,"line":60},"line",1,[57,62,64],{"class":63},"su5hD","numbers ",[57,66,68],{"class":67},"smGrS","=",[57,70,72],{"class":71},"sP7_E"," [",[57,74,76],{"class":75},"srdBf","3",[57,78,79],{"class":71},",",[57,81,82],{"class":75}," 8",[57,84,79],{"class":71},[57,86,87],{"class":75}," 2",[57,89,79],{"class":71},[57,91,92],{"class":75}," 5",[57,94,95],{"class":71},"]\n",[57,97,99,103,106,109,111,115],{"class":59,"line":98},2,[57,100,102],{"class":101},"sptTA","print",[57,104,105],{"class":71},"(",[57,107,108],{"class":101},"max",[57,110,105],{"class":71},[57,112,114],{"class":113},"slqww","numbers",[57,116,117],{"class":71},"))\n",[57,119,121],{"class":59,"line":120},3,[57,122,124],{"emptyLinePlaceholder":123},true,"\n",[57,126,128,130,132,134,136,138,140,142,144,146,148,150],{"class":59,"line":127},4,[57,129,102],{"class":101},[57,131,105],{"class":71},[57,133,108],{"class":101},[57,135,105],{"class":71},[57,137,76],{"class":75},[57,139,79],{"class":71},[57,141,82],{"class":75},[57,143,79],{"class":71},[57,145,87],{"class":75},[57,147,79],{"class":71},[57,149,92],{"class":75},[57,151,117],{"class":71},[57,153,155],{"class":59,"line":154},5,[57,156,124],{"emptyLinePlaceholder":123},[57,158,160,163,165,167,171,175,177,179,182,185,187,189,191,194,196],{"class":59,"line":159},6,[57,161,162],{"class":63},"words ",[57,164,68],{"class":67},[57,166,72],{"class":71},[57,168,170],{"class":169},"sjJ54","\"",[57,172,174],{"class":173},"s_sjI","apple",[57,176,170],{"class":169},[57,178,79],{"class":71},[57,180,181],{"class":169}," \"",[57,183,184],{"class":173},"banana",[57,186,170],{"class":169},[57,188,79],{"class":71},[57,190,181],{"class":169},[57,192,193],{"class":173},"pear",[57,195,170],{"class":169},[57,197,95],{"class":71},[57,199,201,203,205,207,209,212],{"class":59,"line":200},7,[57,202,102],{"class":101},[57,204,105],{"class":71},[57,206,108],{"class":101},[57,208,105],{"class":71},[57,210,211],{"class":113},"words",[57,213,117],{"class":71},[20,215,216],{},"Output:",[48,218,220],{"className":50,"code":219,"language":52,"meta":53,"style":53},"8\n8\npear\n",[15,221,222,227,231],{"__ignoreMap":53},[57,223,224],{"class":59,"line":60},[57,225,226],{"class":75},"8\n",[57,228,229],{"class":59,"line":98},[57,230,226],{"class":75},[57,232,233],{"class":59,"line":120},[57,234,235],{"class":63},"pear\n",[20,237,238],{},"In this example:",[30,240,241,247,253],{},[33,242,243,246],{},[15,244,245],{},"max(numbers)"," uses the iterable form",[33,248,249,252],{},[15,250,251],{},"max(3, 8, 2, 5)"," uses separate arguments",[33,254,255,258],{},[15,256,257],{},"max(words)"," compares strings alphabetically",[43,260,262,263,265],{"id":261},"what-max-does","What ",[15,264,17],{}," does",[20,267,268,270],{},[15,269,17],{},":",[30,272,273,276,279,282],{},[33,274,275],{},"Returns the largest item",[33,277,278],{},"Works with a list, tuple, string, set, or other iterable",[33,280,281],{},"Also works with two or more separate values",[33,283,284],{},"Compares items using Python’s normal ordering rules",[20,286,287],{},"For numbers, “largest” means the highest value.",[20,289,290],{},"For strings, “largest” means the item that comes last in alphabetical order.",[43,292,294],{"id":293},"basic-syntax","Basic syntax",[20,296,297,298,270],{},"Here are the main forms of ",[15,299,17],{},[48,301,303],{"className":50,"code":302,"language":52,"meta":53,"style":53},"max(iterable)\nmax(iterable, *, key=func)\nmax(iterable, *, default=value)\nmax(arg1, arg2, *args)\nmax(arg1, arg2, *args, key=func)\n",[15,304,305,317,343,367,390],{"__ignoreMap":53},[57,306,307,309,311,314],{"class":59,"line":60},[57,308,108],{"class":101},[57,310,105],{"class":71},[57,312,313],{"class":113},"iterable",[57,315,316],{"class":71},")\n",[57,318,319,321,323,325,327,330,332,336,338,341],{"class":59,"line":98},[57,320,108],{"class":101},[57,322,105],{"class":71},[57,324,313],{"class":113},[57,326,79],{"class":71},[57,328,329],{"class":67}," *",[57,331,79],{"class":71},[57,333,335],{"class":334},"s99_P"," key",[57,337,68],{"class":67},[57,339,340],{"class":113},"func",[57,342,316],{"class":71},[57,344,345,347,349,351,353,355,357,360,362,365],{"class":59,"line":120},[57,346,108],{"class":101},[57,348,105],{"class":71},[57,350,313],{"class":113},[57,352,79],{"class":71},[57,354,329],{"class":67},[57,356,79],{"class":71},[57,358,359],{"class":334}," default",[57,361,68],{"class":67},[57,363,364],{"class":113},"value",[57,366,316],{"class":71},[57,368,369,371,373,376,378,381,383,385,388],{"class":59,"line":127},[57,370,108],{"class":101},[57,372,105],{"class":71},[57,374,375],{"class":113},"arg1",[57,377,79],{"class":71},[57,379,380],{"class":113}," arg2",[57,382,79],{"class":71},[57,384,329],{"class":67},[57,386,387],{"class":113},"args",[57,389,316],{"class":71},[57,391,392,394,396,398,400,402,404,406,408,410,412,414,416],{"class":59,"line":154},[57,393,108],{"class":101},[57,395,105],{"class":71},[57,397,375],{"class":113},[57,399,79],{"class":71},[57,401,380],{"class":113},[57,403,79],{"class":71},[57,405,329],{"class":67},[57,407,387],{"class":113},[57,409,79],{"class":71},[57,411,335],{"class":334},[57,413,68],{"class":67},[57,415,340],{"class":113},[57,417,316],{"class":71},[20,419,420],{},"The most important parts are:",[30,422,423,428,434],{},[33,424,425,427],{},[15,426,313],{},": a collection like a list, tuple, or string",[33,429,430,433],{},[15,431,432],{},"key",": a function that tells Python how to compare items",[33,435,436,439],{},[15,437,438],{},"default",": a value to return if the iterable is empty",[43,441,443,444,446],{"id":442},"using-max-with-a-list-of-numbers","Using ",[15,445,17],{}," with a list of numbers",[20,448,449],{},"This is the most common beginner use case.",[48,451,453],{"className":50,"code":452,"language":52,"meta":53,"style":53},"scores = [72, 91, 85, 66]\nhighest_score = max(scores)\n\nprint(highest_score)\n",[15,454,455,484,501,505],{"__ignoreMap":53},[57,456,457,460,462,464,467,469,472,474,477,479,482],{"class":59,"line":60},[57,458,459],{"class":63},"scores ",[57,461,68],{"class":67},[57,463,72],{"class":71},[57,465,466],{"class":75},"72",[57,468,79],{"class":71},[57,470,471],{"class":75}," 91",[57,473,79],{"class":71},[57,475,476],{"class":75}," 85",[57,478,79],{"class":71},[57,480,481],{"class":75}," 66",[57,483,95],{"class":71},[57,485,486,489,491,494,496,499],{"class":59,"line":98},[57,487,488],{"class":63},"highest_score ",[57,490,68],{"class":67},[57,492,493],{"class":101}," max",[57,495,105],{"class":71},[57,497,498],{"class":113},"scores",[57,500,316],{"class":71},[57,502,503],{"class":59,"line":120},[57,504,124],{"emptyLinePlaceholder":123},[57,506,507,509,511,514],{"class":59,"line":127},[57,508,102],{"class":101},[57,510,105],{"class":71},[57,512,513],{"class":113},"highest_score",[57,515,316],{"class":71},[20,517,216],{},[48,519,521],{"className":50,"code":520,"language":52,"meta":53,"style":53},"91\n",[15,522,523],{"__ignoreMap":53},[57,524,525],{"class":59,"line":60},[57,526,520],{"class":75},[20,528,529],{},"This works well for:",[30,531,532,535,538,541],{},[33,533,534],{},"Scores",[33,536,537],{},"Prices",[33,539,540],{},"Ages",[33,542,543],{},"Counts",[20,545,546],{},"Another example:",[48,548,550],{"className":50,"code":549,"language":52,"meta":53,"style":53},"prices = [19.99, 5.50, 12.75, 29.00]\nprint(max(prices))\n",[15,551,552,581],{"__ignoreMap":53},[57,553,554,557,559,561,564,566,569,571,574,576,579],{"class":59,"line":60},[57,555,556],{"class":63},"prices ",[57,558,68],{"class":67},[57,560,72],{"class":71},[57,562,563],{"class":75},"19.99",[57,565,79],{"class":71},[57,567,568],{"class":75}," 5.50",[57,570,79],{"class":71},[57,572,573],{"class":75}," 12.75",[57,575,79],{"class":71},[57,577,578],{"class":75}," 29.00",[57,580,95],{"class":71},[57,582,583,585,587,589,591,594],{"class":59,"line":98},[57,584,102],{"class":101},[57,586,105],{"class":71},[57,588,108],{"class":101},[57,590,105],{"class":71},[57,592,593],{"class":113},"prices",[57,595,117],{"class":71},[20,597,216],{},[48,599,601],{"className":50,"code":600,"language":52,"meta":53,"style":53},"29.0\n",[15,602,603],{"__ignoreMap":53},[57,604,605],{"class":59,"line":60},[57,606,600],{"class":75},[20,608,609,610,612,613,620],{},"If you only need the largest value, ",[15,611,17],{}," is simpler than ",[614,615,617],"a",{"href":616},"\u002Freference\u002Fpython-sorted-function-explained\u002F",[15,618,619],{},"sorted()",".",[43,622,443,624,626],{"id":623},"using-max-with-separate-values",[15,625,17],{}," with separate values",[20,628,629],{},"You do not always need a list. You can pass values directly.",[48,631,633],{"className":50,"code":632,"language":52,"meta":53,"style":53},"print(max(4, 12, 7))\n",[15,634,635],{"__ignoreMap":53},[57,636,637,639,641,643,645,648,650,653,655,658],{"class":59,"line":60},[57,638,102],{"class":101},[57,640,105],{"class":71},[57,642,108],{"class":101},[57,644,105],{"class":71},[57,646,647],{"class":75},"4",[57,649,79],{"class":71},[57,651,652],{"class":75}," 12",[57,654,79],{"class":71},[57,656,657],{"class":75}," 7",[57,659,117],{"class":71},[20,661,216],{},[48,663,665],{"className":50,"code":664,"language":52,"meta":53,"style":53},"12\n",[15,666,667],{"__ignoreMap":53},[57,668,669],{"class":59,"line":60},[57,670,664],{"class":75},[20,672,673],{},"This is useful for quick comparisons.",[20,675,676],{},"For example, comparing three numbers entered by a user:",[48,678,680],{"className":50,"code":679,"language":52,"meta":53,"style":53},"a = 15\nb = 42\nc = 27\n\nlargest = max(a, b, c)\nprint(largest)\n",[15,681,682,692,702,712,716,741],{"__ignoreMap":53},[57,683,684,687,689],{"class":59,"line":60},[57,685,686],{"class":63},"a ",[57,688,68],{"class":67},[57,690,691],{"class":75}," 15\n",[57,693,694,697,699],{"class":59,"line":98},[57,695,696],{"class":63},"b ",[57,698,68],{"class":67},[57,700,701],{"class":75}," 42\n",[57,703,704,707,709],{"class":59,"line":120},[57,705,706],{"class":63},"c ",[57,708,68],{"class":67},[57,710,711],{"class":75}," 27\n",[57,713,714],{"class":59,"line":127},[57,715,124],{"emptyLinePlaceholder":123},[57,717,718,721,723,725,727,729,731,734,736,739],{"class":59,"line":154},[57,719,720],{"class":63},"largest ",[57,722,68],{"class":67},[57,724,493],{"class":101},[57,726,105],{"class":71},[57,728,614],{"class":113},[57,730,79],{"class":71},[57,732,733],{"class":113}," b",[57,735,79],{"class":71},[57,737,738],{"class":113}," c",[57,740,316],{"class":71},[57,742,743,745,747,750],{"class":59,"line":159},[57,744,102],{"class":101},[57,746,105],{"class":71},[57,748,749],{"class":113},"largest",[57,751,316],{"class":71},[20,753,216],{},[48,755,757],{"className":50,"code":756,"language":52,"meta":53,"style":53},"42\n",[15,758,759],{"__ignoreMap":53},[57,760,761],{"class":59,"line":60},[57,762,756],{"class":75},[20,764,765],{},"Use this form when you already have separate values and do not need to store them in a list first.",[43,767,443,769,771],{"id":768},"using-max-with-strings",[15,770,17],{}," with strings",[20,773,774,776],{},[15,775,17],{}," can compare strings too.",[48,778,780],{"className":50,"code":779,"language":52,"meta":53,"style":53},"words = [\"apple\", \"banana\", \"pear\"]\nprint(max(words))\n",[15,781,782,814],{"__ignoreMap":53},[57,783,784,786,788,790,792,794,796,798,800,802,804,806,808,810,812],{"class":59,"line":60},[57,785,162],{"class":63},[57,787,68],{"class":67},[57,789,72],{"class":71},[57,791,170],{"class":169},[57,793,174],{"class":173},[57,795,170],{"class":169},[57,797,79],{"class":71},[57,799,181],{"class":169},[57,801,184],{"class":173},[57,803,170],{"class":169},[57,805,79],{"class":71},[57,807,181],{"class":169},[57,809,193],{"class":173},[57,811,170],{"class":169},[57,813,95],{"class":71},[57,815,816,818,820,822,824,826],{"class":59,"line":98},[57,817,102],{"class":101},[57,819,105],{"class":71},[57,821,108],{"class":101},[57,823,105],{"class":71},[57,825,211],{"class":113},[57,827,117],{"class":71},[20,829,216],{},[48,831,832],{"className":50,"code":235,"language":52,"meta":53,"style":53},[15,833,834],{"__ignoreMap":53},[57,835,836],{"class":59,"line":60},[57,837,235],{"class":63},[20,839,840],{},"This happens because strings are compared alphabetically.",[20,842,843],{},"A few important points:",[30,845,846,856,859],{},[33,847,848,851,852,855],{},[15,849,850],{},"\"pear\""," comes after ",[15,853,854],{},"\"banana\""," alphabetically",[33,857,858],{},"Uppercase and lowercase letters can change the result",[33,860,861],{},"Mixed text case can surprise beginners",[20,863,864],{},"Example:",[48,866,868],{"className":50,"code":867,"language":52,"meta":53,"style":53},"words = [\"apple\", \"Banana\", \"pear\"]\nprint(max(words))\n",[15,869,870,903],{"__ignoreMap":53},[57,871,872,874,876,878,880,882,884,886,888,891,893,895,897,899,901],{"class":59,"line":60},[57,873,162],{"class":63},[57,875,68],{"class":67},[57,877,72],{"class":71},[57,879,170],{"class":169},[57,881,174],{"class":173},[57,883,170],{"class":169},[57,885,79],{"class":71},[57,887,181],{"class":169},[57,889,890],{"class":173},"Banana",[57,892,170],{"class":169},[57,894,79],{"class":71},[57,896,181],{"class":169},[57,898,193],{"class":173},[57,900,170],{"class":169},[57,902,95],{"class":71},[57,904,905,907,909,911,913,915],{"class":59,"line":98},[57,906,102],{"class":101},[57,908,105],{"class":71},[57,910,108],{"class":101},[57,912,105],{"class":71},[57,914,211],{"class":113},[57,916,117],{"class":71},[20,918,919],{},"The result may not be what you expect because uppercase letters are compared differently from lowercase letters.",[20,921,922,923,925],{},"You can fix that with the ",[15,924,432],{}," argument, which is explained below.",[43,927,929,930,932],{"id":928},"using-the-key-argument","Using the ",[15,931,432],{}," argument",[20,934,935,936,938],{},"The ",[15,937,432],{}," argument lets you control how items are compared.",[20,940,941],{},"This is very useful when the “largest” item is not simply the normal largest value.",[943,944,946],"h3",{"id":945},"find-the-longest-word","Find the longest word",[48,948,950],{"className":50,"code":949,"language":52,"meta":53,"style":53},"words = [\"cat\", \"elephant\", \"dog\"]\nprint(max(words, key=len))\n",[15,951,952,987],{"__ignoreMap":53},[57,953,954,956,958,960,962,965,967,969,971,974,976,978,980,983,985],{"class":59,"line":60},[57,955,162],{"class":63},[57,957,68],{"class":67},[57,959,72],{"class":71},[57,961,170],{"class":169},[57,963,964],{"class":173},"cat",[57,966,170],{"class":169},[57,968,79],{"class":71},[57,970,181],{"class":169},[57,972,973],{"class":173},"elephant",[57,975,170],{"class":169},[57,977,79],{"class":71},[57,979,181],{"class":169},[57,981,982],{"class":173},"dog",[57,984,170],{"class":169},[57,986,95],{"class":71},[57,988,989,991,993,995,997,999,1001,1003,1005,1008],{"class":59,"line":98},[57,990,102],{"class":101},[57,992,105],{"class":71},[57,994,108],{"class":101},[57,996,105],{"class":71},[57,998,211],{"class":113},[57,1000,79],{"class":71},[57,1002,335],{"class":334},[57,1004,68],{"class":67},[57,1006,1007],{"class":101},"len",[57,1009,117],{"class":71},[20,1011,216],{},[48,1013,1015],{"className":50,"code":1014,"language":52,"meta":53,"style":53},"elephant\n",[15,1016,1017],{"__ignoreMap":53},[57,1018,1019],{"class":59,"line":60},[57,1020,1014],{"class":63},[20,1022,1023,1024,1027],{},"Here, ",[15,1025,1026],{},"key=len"," tells Python to compare the lengths of the strings instead of the strings themselves.",[20,1029,1030,1031,1034,1035,620],{},"If you are new to ",[15,1032,1033],{},"len()",", see ",[614,1036,1038,1040],{"href":1037},"\u002Freference\u002Fpython-len-function-explained\u002F",[15,1039,1033],{}," explained",[943,1042,1044],{"id":1043},"compare-strings-without-caring-about-uppercase-or-lowercase","Compare strings without caring about uppercase or lowercase",[48,1046,1048],{"className":50,"code":1047,"language":52,"meta":53,"style":53},"words = [\"apple\", \"Banana\", \"pear\"]\nprint(max(words, key=str.lower))\n",[15,1049,1050,1082],{"__ignoreMap":53},[57,1051,1052,1054,1056,1058,1060,1062,1064,1066,1068,1070,1072,1074,1076,1078,1080],{"class":59,"line":60},[57,1053,162],{"class":63},[57,1055,68],{"class":67},[57,1057,72],{"class":71},[57,1059,170],{"class":169},[57,1061,174],{"class":173},[57,1063,170],{"class":169},[57,1065,79],{"class":71},[57,1067,181],{"class":169},[57,1069,890],{"class":173},[57,1071,170],{"class":169},[57,1073,79],{"class":71},[57,1075,181],{"class":169},[57,1077,193],{"class":173},[57,1079,170],{"class":169},[57,1081,95],{"class":71},[57,1083,1084,1086,1088,1090,1092,1094,1096,1098,1100,1104,1106,1110],{"class":59,"line":98},[57,1085,102],{"class":101},[57,1087,105],{"class":71},[57,1089,108],{"class":101},[57,1091,105],{"class":71},[57,1093,211],{"class":113},[57,1095,79],{"class":71},[57,1097,335],{"class":334},[57,1099,68],{"class":67},[57,1101,1103],{"class":1102},"sZMiF","str",[57,1105,620],{"class":71},[57,1107,1109],{"class":1108},"skxfh","lower",[57,1111,117],{"class":71},[20,1113,216],{},[48,1115,1116],{"className":50,"code":235,"language":52,"meta":53,"style":53},[15,1117,1118],{"__ignoreMap":53},[57,1119,1120],{"class":59,"line":60},[57,1121,235],{"class":63},[20,1123,1023,1124,1127],{},[15,1125,1126],{},"str.lower"," converts each string to lowercase for comparison.",[943,1129,1131],{"id":1130},"use-a-lambda-function","Use a lambda function",[20,1133,1134,1135,270],{},"You can also use a small custom function with ",[15,1136,1137],{},"lambda",[48,1139,1141],{"className":50,"code":1140,"language":52,"meta":53,"style":53},"items = [\"a\", \"bb\", \"cccc\", \"ddd\"]\nprint(max(items, key=lambda text: len(text)))\n",[15,1142,1143,1187],{"__ignoreMap":53},[57,1144,1145,1148,1150,1152,1154,1156,1158,1160,1162,1165,1167,1169,1171,1174,1176,1178,1180,1183,1185],{"class":59,"line":60},[57,1146,1147],{"class":63},"items ",[57,1149,68],{"class":67},[57,1151,72],{"class":71},[57,1153,170],{"class":169},[57,1155,614],{"class":173},[57,1157,170],{"class":169},[57,1159,79],{"class":71},[57,1161,181],{"class":169},[57,1163,1164],{"class":173},"bb",[57,1166,170],{"class":169},[57,1168,79],{"class":71},[57,1170,181],{"class":169},[57,1172,1173],{"class":173},"cccc",[57,1175,170],{"class":169},[57,1177,79],{"class":71},[57,1179,181],{"class":169},[57,1181,1182],{"class":173},"ddd",[57,1184,170],{"class":169},[57,1186,95],{"class":71},[57,1188,1189,1191,1193,1195,1197,1200,1202,1204,1206,1209,1213,1215,1218,1220,1223],{"class":59,"line":98},[57,1190,102],{"class":101},[57,1192,105],{"class":71},[57,1194,108],{"class":101},[57,1196,105],{"class":71},[57,1198,1199],{"class":113},"items",[57,1201,79],{"class":71},[57,1203,335],{"class":334},[57,1205,68],{"class":67},[57,1207,1137],{"class":1208},"sbsja",[57,1210,1212],{"class":1211},"sFwrP"," text",[57,1214,270],{"class":71},[57,1216,1217],{"class":101}," len",[57,1219,105],{"class":71},[57,1221,1222],{"class":113},"text",[57,1224,1225],{"class":71},")))\n",[20,1227,216],{},[48,1229,1231],{"className":50,"code":1230,"language":52,"meta":53,"style":53},"cccc\n",[15,1232,1233],{"__ignoreMap":53},[57,1234,1235],{"class":59,"line":60},[57,1236,1230],{"class":63},[20,1238,1239,1240,1242,1243,1246],{},"For beginners, ",[15,1241,1026],{}," and ",[15,1244,1245],{},"key=str.lower"," are the most useful examples to remember.",[43,1248,929,1250,932],{"id":1249},"using-the-default-argument",[15,1251,438],{},[20,1253,935,1254,1256],{},[15,1255,438],{}," argument only works with the iterable form.",[20,1258,1259],{},"It prevents an error when the iterable is empty.",[48,1261,1263],{"className":50,"code":1262,"language":52,"meta":53,"style":53},"numbers = []\nprint(max(numbers, default=0))\n",[15,1264,1265,1274],{"__ignoreMap":53},[57,1266,1267,1269,1271],{"class":59,"line":60},[57,1268,64],{"class":63},[57,1270,68],{"class":67},[57,1272,1273],{"class":71}," []\n",[57,1275,1276,1278,1280,1282,1284,1286,1288,1290,1292,1295],{"class":59,"line":98},[57,1277,102],{"class":101},[57,1279,105],{"class":71},[57,1281,108],{"class":101},[57,1283,105],{"class":71},[57,1285,114],{"class":113},[57,1287,79],{"class":71},[57,1289,359],{"class":334},[57,1291,68],{"class":67},[57,1293,1294],{"class":75},"0",[57,1296,117],{"class":71},[20,1298,216],{},[48,1300,1302],{"className":50,"code":1301,"language":52,"meta":53,"style":53},"0\n",[15,1303,1304],{"__ignoreMap":53},[57,1305,1306],{"class":59,"line":60},[57,1307,1301],{"class":75},[20,1309,1310],{},"This is helpful when a list may have no items.",[20,1312,1313,1314,1316],{},"Without ",[15,1315,438],{},", this would raise an error.",[20,1318,546],{},[48,1320,1322],{"className":50,"code":1321,"language":52,"meta":53,"style":53},"words = []\nresult = max(words, default=\"no words found\")\nprint(result)\n",[15,1323,1324,1332,1360],{"__ignoreMap":53},[57,1325,1326,1328,1330],{"class":59,"line":60},[57,1327,162],{"class":63},[57,1329,68],{"class":67},[57,1331,1273],{"class":71},[57,1333,1334,1337,1339,1341,1343,1345,1347,1349,1351,1353,1356,1358],{"class":59,"line":98},[57,1335,1336],{"class":63},"result ",[57,1338,68],{"class":67},[57,1340,493],{"class":101},[57,1342,105],{"class":71},[57,1344,211],{"class":113},[57,1346,79],{"class":71},[57,1348,359],{"class":334},[57,1350,68],{"class":67},[57,1352,170],{"class":169},[57,1354,1355],{"class":173},"no words found",[57,1357,170],{"class":169},[57,1359,316],{"class":71},[57,1361,1362,1364,1366,1369],{"class":59,"line":120},[57,1363,102],{"class":101},[57,1365,105],{"class":71},[57,1367,1368],{"class":113},"result",[57,1370,316],{"class":71},[20,1372,216],{},[48,1374,1376],{"className":50,"code":1375,"language":52,"meta":53,"style":53},"no words found\n",[15,1377,1378],{"__ignoreMap":53},[57,1379,1380],{"class":59,"line":60},[57,1381,1375],{"class":63},[20,1383,1384],{},"Important:",[30,1386,1387,1395],{},[33,1388,1389,1391,1392],{},[15,1390,438],{}," works with ",[15,1393,1394],{},"max(iterable, default=value)",[33,1396,1397,1398,1402,1403],{},"It does ",[1399,1400,1401],"strong",{},"not"," work with multiple separate arguments like ",[15,1404,1405],{},"max(1, 2, 3, default=0)",[43,1407,1409],{"id":1408},"what-errors-can-happen","What errors can happen",[20,1411,1412,1413,620],{},"There are a few common errors when using ",[15,1414,17],{},[943,1416,1418,1421],{"id":1417},"valueerror-with-an-empty-iterable",[15,1419,1420],{},"ValueError"," with an empty iterable",[20,1423,1424,1425,1427,1428,620],{},"If the iterable is empty and you do not provide ",[15,1426,438],{},", Python raises a ",[15,1429,1420],{},[48,1431,1433],{"className":50,"code":1432,"language":52,"meta":53,"style":53},"numbers = []\nprint(max(numbers))\n",[15,1434,1435,1443],{"__ignoreMap":53},[57,1436,1437,1439,1441],{"class":59,"line":60},[57,1438,64],{"class":63},[57,1440,68],{"class":67},[57,1442,1273],{"class":71},[57,1444,1445,1447,1449,1451,1453,1455],{"class":59,"line":98},[57,1446,102],{"class":101},[57,1448,105],{"class":71},[57,1450,108],{"class":101},[57,1452,105],{"class":71},[57,1454,114],{"class":113},[57,1456,117],{"class":71},[20,1458,1459],{},"Error:",[48,1461,1463],{"className":50,"code":1462,"language":52,"meta":53,"style":53},"ValueError: max() arg is an empty sequence\n",[15,1464,1465],{"__ignoreMap":53},[57,1466,1467,1469,1471,1473,1476,1479,1482],{"class":59,"line":60},[57,1468,1420],{"class":1102},[57,1470,270],{"class":71},[57,1472,493],{"class":101},[57,1474,1475],{"class":71},"()",[57,1477,1478],{"class":63}," arg ",[57,1480,1481],{"class":67},"is",[57,1483,1484],{"class":63}," an empty sequence\n",[20,1486,1487,1488,270],{},"Fix it by using ",[15,1489,438],{},[48,1491,1493],{"className":50,"code":1492,"language":52,"meta":53,"style":53},"numbers = []\nprint(max(numbers, default=None))\n",[15,1494,1495,1503],{"__ignoreMap":53},[57,1496,1497,1499,1501],{"class":59,"line":60},[57,1498,64],{"class":63},[57,1500,68],{"class":67},[57,1502,1273],{"class":71},[57,1504,1505,1507,1509,1511,1513,1515,1517,1519,1521,1525],{"class":59,"line":98},[57,1506,102],{"class":101},[57,1508,105],{"class":71},[57,1510,108],{"class":101},[57,1512,105],{"class":71},[57,1514,114],{"class":113},[57,1516,79],{"class":71},[57,1518,359],{"class":334},[57,1520,68],{"class":67},[57,1522,1524],{"class":1523},"s39Yj","None",[57,1526,117],{"class":71},[20,1528,1529,1530,620],{},"If you need more help with this kind of problem, see ",[614,1531,1533],{"href":1532},"\u002Ferrors\u002Fvalueerror-in-python-causes-and-fixes\u002F","ValueError in Python: causes and fixes",[943,1535,1537,1540],{"id":1536},"typeerror-when-items-cannot-be-compared",[15,1538,1539],{},"TypeError"," when items cannot be compared",[20,1542,1543,1544,620],{},"If Python cannot compare the items, you get a ",[15,1545,1539],{},[48,1547,1549],{"className":50,"code":1548,"language":52,"meta":53,"style":53},"items = [10, \"20\", 30]\nprint(max(items))\n",[15,1550,1551,1578],{"__ignoreMap":53},[57,1552,1553,1555,1557,1559,1562,1564,1566,1569,1571,1573,1576],{"class":59,"line":60},[57,1554,1147],{"class":63},[57,1556,68],{"class":67},[57,1558,72],{"class":71},[57,1560,1561],{"class":75},"10",[57,1563,79],{"class":71},[57,1565,181],{"class":169},[57,1567,1568],{"class":173},"20",[57,1570,170],{"class":169},[57,1572,79],{"class":71},[57,1574,1575],{"class":75}," 30",[57,1577,95],{"class":71},[57,1579,1580,1582,1584,1586,1588,1590],{"class":59,"line":98},[57,1581,102],{"class":101},[57,1583,105],{"class":71},[57,1585,108],{"class":101},[57,1587,105],{"class":71},[57,1589,1199],{"class":113},[57,1591,117],{"class":71},[20,1593,1594],{},"This fails because integers and strings are different types and cannot be compared normally.",[20,1596,1597],{},"Fix it by making the items the same type:",[48,1599,1601],{"className":50,"code":1600,"language":52,"meta":53,"style":53},"items = [10, 20, 30]\nprint(max(items))\n",[15,1602,1603,1624],{"__ignoreMap":53},[57,1604,1605,1607,1609,1611,1613,1615,1618,1620,1622],{"class":59,"line":60},[57,1606,1147],{"class":63},[57,1608,68],{"class":67},[57,1610,72],{"class":71},[57,1612,1561],{"class":75},[57,1614,79],{"class":71},[57,1616,1617],{"class":75}," 20",[57,1619,79],{"class":71},[57,1621,1575],{"class":75},[57,1623,95],{"class":71},[57,1625,1626,1628,1630,1632,1634,1636],{"class":59,"line":98},[57,1627,102],{"class":101},[57,1629,105],{"class":71},[57,1631,108],{"class":101},[57,1633,105],{"class":71},[57,1635,1199],{"class":113},[57,1637,117],{"class":71},[20,1639,1640,1641,620],{},"If you are debugging this kind of issue, see ",[614,1642,1644],{"href":1643},"\u002Ferrors\u002Ftypeerror-vs-valueerror-in-python-explained","TypeError in Python: causes and fixes",[943,1646,1648,1650],{"id":1647},"typeerror-when-called-with-no-arguments",[15,1649,1539],{}," when called with no arguments",[20,1652,1653,1655],{},[15,1654,17],{}," needs at least one iterable or at least two values.",[48,1657,1659],{"className":50,"code":1658,"language":52,"meta":53,"style":53},"print(max())\n",[15,1660,1661],{"__ignoreMap":53},[57,1662,1663,1665,1667,1669],{"class":59,"line":60},[57,1664,102],{"class":101},[57,1666,105],{"class":71},[57,1668,108],{"class":101},[57,1670,1671],{"class":71},"())\n",[20,1673,1674,1675,620],{},"This raises a ",[15,1676,1539],{},[43,1678,1680,1682,1683],{"id":1679},"max-vs-sorted",[15,1681,17],{}," vs ",[15,1684,619],{},[20,1686,1687],{},"These two functions are related, but they do different things.",[20,1689,1690,270],{},[15,1691,17],{},[30,1693,1694],{},[33,1695,1696],{},"Returns one largest item",[20,1698,1699,270],{},[15,1700,619],{},[30,1702,1703],{},[33,1704,1705],{},"Returns a new sorted list of all items",[20,1707,864],{},[48,1709,1711],{"className":50,"code":1710,"language":52,"meta":53,"style":53},"numbers = [3, 8, 2, 5]\n\nprint(max(numbers))\nprint(sorted(numbers))\n",[15,1712,1713,1737,1741,1755],{"__ignoreMap":53},[57,1714,1715,1717,1719,1721,1723,1725,1727,1729,1731,1733,1735],{"class":59,"line":60},[57,1716,64],{"class":63},[57,1718,68],{"class":67},[57,1720,72],{"class":71},[57,1722,76],{"class":75},[57,1724,79],{"class":71},[57,1726,82],{"class":75},[57,1728,79],{"class":71},[57,1730,87],{"class":75},[57,1732,79],{"class":71},[57,1734,92],{"class":75},[57,1736,95],{"class":71},[57,1738,1739],{"class":59,"line":98},[57,1740,124],{"emptyLinePlaceholder":123},[57,1742,1743,1745,1747,1749,1751,1753],{"class":59,"line":120},[57,1744,102],{"class":101},[57,1746,105],{"class":71},[57,1748,108],{"class":101},[57,1750,105],{"class":71},[57,1752,114],{"class":113},[57,1754,117],{"class":71},[57,1756,1757,1759,1761,1764,1766,1768],{"class":59,"line":127},[57,1758,102],{"class":101},[57,1760,105],{"class":71},[57,1762,1763],{"class":101},"sorted",[57,1765,105],{"class":71},[57,1767,114],{"class":113},[57,1769,117],{"class":71},[20,1771,216],{},[48,1773,1775],{"className":50,"code":1774,"language":52,"meta":53,"style":53},"8\n[2, 3, 5, 8]\n",[15,1776,1777,1781],{"__ignoreMap":53},[57,1778,1779],{"class":59,"line":60},[57,1780,226],{"class":75},[57,1782,1783,1786,1789,1791,1794,1796,1798,1800,1802],{"class":59,"line":98},[57,1784,1785],{"class":71},"[",[57,1787,1788],{"class":75},"2",[57,1790,79],{"class":71},[57,1792,1793],{"class":75}," 3",[57,1795,79],{"class":71},[57,1797,92],{"class":75},[57,1799,79],{"class":71},[57,1801,82],{"class":75},[57,1803,95],{"class":71},[20,1805,1806,1807,1809],{},"Use ",[15,1808,17],{}," when you only need the largest value.",[20,1811,1806,1812,1816],{},[614,1813,1814],{"href":616},[15,1815,619],{}," when you need all items in order.",[20,1818,1819,1820,620],{},"If you want the smallest item instead, compare this with ",[614,1821,1823],{"href":1822},"\u002Freference\u002Fpython-min-function-explained\u002F",[15,1824,1825],{},"min()",[43,1827,1829],{"id":1828},"common-mistakes","Common mistakes",[20,1831,1832],{},"Beginners often run into these problems:",[30,1834,1835,1843,1846,1852,1855],{},[33,1836,1837,1838,1840,1841],{},"Calling ",[15,1839,17],{}," on an empty list without ",[15,1842,438],{},[33,1844,1845],{},"Mixing incompatible types like integers and strings",[33,1847,1848,1849,1851],{},"Expecting ",[15,1850,17],{}," to return all large items instead of one item",[33,1853,1854],{},"Forgetting that strings are compared alphabetically",[33,1856,443,1857,1859],{},[15,1858,438],{}," with multiple separate arguments",[20,1861,1862],{},"If something is not working, these quick checks can help:",[48,1864,1866],{"className":50,"code":1865,"language":52,"meta":53,"style":53},"print(items)\nprint(type(items))\nprint(len(items))\nprint(max(items))\nprint(max(items, default=None))\nprint([type(x) for x in items])\n",[15,1867,1868,1878,1893,1907,1921,1943],{"__ignoreMap":53},[57,1869,1870,1872,1874,1876],{"class":59,"line":60},[57,1871,102],{"class":101},[57,1873,105],{"class":71},[57,1875,1199],{"class":113},[57,1877,316],{"class":71},[57,1879,1880,1882,1884,1887,1889,1891],{"class":59,"line":98},[57,1881,102],{"class":101},[57,1883,105],{"class":71},[57,1885,1886],{"class":1102},"type",[57,1888,105],{"class":71},[57,1890,1199],{"class":113},[57,1892,117],{"class":71},[57,1894,1895,1897,1899,1901,1903,1905],{"class":59,"line":120},[57,1896,102],{"class":101},[57,1898,105],{"class":71},[57,1900,1007],{"class":101},[57,1902,105],{"class":71},[57,1904,1199],{"class":113},[57,1906,117],{"class":71},[57,1908,1909,1911,1913,1915,1917,1919],{"class":59,"line":127},[57,1910,102],{"class":101},[57,1912,105],{"class":71},[57,1914,108],{"class":101},[57,1916,105],{"class":71},[57,1918,1199],{"class":113},[57,1920,117],{"class":71},[57,1922,1923,1925,1927,1929,1931,1933,1935,1937,1939,1941],{"class":59,"line":154},[57,1924,102],{"class":101},[57,1926,105],{"class":71},[57,1928,108],{"class":101},[57,1930,105],{"class":71},[57,1932,1199],{"class":113},[57,1934,79],{"class":71},[57,1936,359],{"class":334},[57,1938,68],{"class":67},[57,1940,1524],{"class":1523},[57,1942,117],{"class":71},[57,1944,1945,1947,1950,1952,1954,1957,1960,1964,1967,1970,1973],{"class":59,"line":159},[57,1946,102],{"class":101},[57,1948,1949],{"class":71},"([",[57,1951,1886],{"class":1102},[57,1953,105],{"class":71},[57,1955,1956],{"class":113},"x",[57,1958,1959],{"class":71},")",[57,1961,1963],{"class":1962},"sVHd0"," for",[57,1965,1966],{"class":113}," x ",[57,1968,1969],{"class":1962},"in",[57,1971,1972],{"class":113}," items",[57,1974,1975],{"class":71},"])\n",[20,1977,1978],{},"These are useful for checking:",[30,1980,1981,1986,1992,1995],{},[33,1982,1983,1984],{},"What is actually inside ",[15,1985,1199],{},[33,1987,1988,1989,1991],{},"Whether ",[15,1990,1199],{}," is a list or some other type",[33,1993,1994],{},"Whether the iterable is empty",[33,1996,1997],{},"Whether all items have compatible types",[20,1999,2000,2001,2004,2005,2007],{},"Be careful with ",[15,2002,2003],{},"print(max(items))"," if ",[15,2006,1199],{}," might be empty or contain mixed types, because that line can also raise an error.",[43,2009,2011],{"id":2010},"faq","FAQ",[943,2013,2015,2016,2018],{"id":2014},"what-does-max-return-in-python","What does ",[15,2017,17],{}," return in Python?",[20,2020,2021],{},"It returns the largest item from an iterable or the largest of two or more values.",[943,2023,2025,2026,2028],{"id":2024},"can-max-work-with-strings","Can ",[15,2027,17],{}," work with strings?",[20,2030,2031],{},"Yes. It compares strings using alphabetical order, based on character values.",[943,2033,2035],{"id":2034},"what-happens-if-the-list-is-empty","What happens if the list is empty?",[20,2037,2038,2040,2041,2043,2044,2046],{},[15,2039,17],{}," raises a ",[15,2042,1420],{}," unless you use the ",[15,2045,438],{}," argument with the iterable form.",[943,2048,2050,2051,2053],{"id":2049},"how-do-i-get-the-longest-string-with-max","How do I get the longest string with ",[15,2052,17],{},"?",[20,2055,1806,2056,270],{},[15,2057,1026],{},[48,2059,2060],{"className":50,"code":949,"language":52,"meta":53,"style":53},[15,2061,2062,2094],{"__ignoreMap":53},[57,2063,2064,2066,2068,2070,2072,2074,2076,2078,2080,2082,2084,2086,2088,2090,2092],{"class":59,"line":60},[57,2065,162],{"class":63},[57,2067,68],{"class":67},[57,2069,72],{"class":71},[57,2071,170],{"class":169},[57,2073,964],{"class":173},[57,2075,170],{"class":169},[57,2077,79],{"class":71},[57,2079,181],{"class":169},[57,2081,973],{"class":173},[57,2083,170],{"class":169},[57,2085,79],{"class":71},[57,2087,181],{"class":169},[57,2089,982],{"class":173},[57,2091,170],{"class":169},[57,2093,95],{"class":71},[57,2095,2096,2098,2100,2102,2104,2106,2108,2110,2112,2114],{"class":59,"line":98},[57,2097,102],{"class":101},[57,2099,105],{"class":71},[57,2101,108],{"class":101},[57,2103,105],{"class":71},[57,2105,211],{"class":113},[57,2107,79],{"class":71},[57,2109,335],{"class":334},[57,2111,68],{"class":67},[57,2113,1007],{"class":101},[57,2115,117],{"class":71},[943,2117,2119,2120,1242,2122,2053],{"id":2118},"what-is-the-difference-between-max-and-sorted","What is the difference between ",[15,2121,17],{},[15,2123,619],{},[20,2125,2126,2128,2129,2131],{},[15,2127,17],{}," returns one largest item. ",[15,2130,619],{}," returns all items in order.",[43,2133,2135],{"id":2134},"see-also","See also",[30,2137,2138,2145,2151,2157,2163,2167],{},[33,2139,2140],{},[614,2141,2142,2144],{"href":1822},[15,2143,1825],{}," function explained",[33,2146,2147],{},[614,2148,2149,2144],{"href":616},[15,2150,619],{},[33,2152,2153],{},[614,2154,2155,2144],{"href":1037},[15,2156,1033],{},[33,2158,2159],{},[614,2160,2162],{"href":2161},"\u002Fhow-to\u002Fhow-to-find-an-item-in-a-list-in-python\u002F","How to find an item in a list in Python",[33,2164,2165],{},[614,2166,1533],{"href":1532},[33,2168,2169],{},[614,2170,1644],{"href":1643},[2172,2173,2174],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sFwrP, html code.shiki .sFwrP{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#24292E;--shiki-default-font-style:inherit;--shiki-dark:#E1E4E8;--shiki-dark-font-style:inherit}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}",{"title":53,"searchDepth":98,"depth":98,"links":2176},[2177,2178,2180,2181,2183,2185,2187,2193,2195,2203,2205,2206,2217],{"id":45,"depth":98,"text":46},{"id":261,"depth":98,"text":2179},"What max() does",{"id":293,"depth":98,"text":294},{"id":442,"depth":98,"text":2182},"Using max() with a list of numbers",{"id":623,"depth":98,"text":2184},"Using max() with separate values",{"id":768,"depth":98,"text":2186},"Using max() with strings",{"id":928,"depth":98,"text":2188,"children":2189},"Using the key argument",[2190,2191,2192],{"id":945,"depth":120,"text":946},{"id":1043,"depth":120,"text":1044},{"id":1130,"depth":120,"text":1131},{"id":1249,"depth":98,"text":2194},"Using the default argument",{"id":1408,"depth":98,"text":1409,"children":2196},[2197,2199,2201],{"id":1417,"depth":120,"text":2198},"ValueError with an empty iterable",{"id":1536,"depth":120,"text":2200},"TypeError when items cannot be compared",{"id":1647,"depth":120,"text":2202},"TypeError when called with no arguments",{"id":1679,"depth":98,"text":2204},"max() vs sorted()",{"id":1828,"depth":98,"text":1829},{"id":2010,"depth":98,"text":2011,"children":2207},[2208,2210,2212,2213,2215],{"id":2014,"depth":120,"text":2209},"What does max() return in Python?",{"id":2024,"depth":120,"text":2211},"Can max() work with strings?",{"id":2034,"depth":120,"text":2035},{"id":2049,"depth":120,"text":2214},"How do I get the longest string with max()?",{"id":2118,"depth":120,"text":2216},"What is the difference between max() and sorted()?",{"id":2134,"depth":98,"text":2135},"Master python max function explained in our comprehensive Python beginner guide.","md",{},"\u002Freference\u002Fpython-max-function-explained",{"title":5,"description":2218},"reference\u002Fpython-max-function-explained","hvpxLEK57awlwmwmUnkeI93490TdK4SLeAU63KWEzvc",1777585489593]