Python standard library: Built-in Functions Max (iterable, *[, key, default])

Source: Internet
Author: User
Tags iterable

Max (Arg1, arg2, *args[, key])

This function is to iterate over the object iterable to find out the maximum value to return. When the key parameter is not empty, it is judged by the function object of key.

Example:

#max () Array1 = Range (Ten) Array2 = Range (0, 3) print (' max (array1) = ', Max (array1)) print (' max (array2) = ', Max (array2)) Print (' Max (array1, ') = ', Max (array1, Key=lambda x:x > 3)) print (max (1, 2)) (max (' ah ', ' BF ', Key=lambda x:x[1]) prin T (Max (array1, Array2, Key=lambda x:x[1]) def comparator (x):   return X[2]print (max (' Ah2 ', ' bf3 ', Key=comparator))

The resulting output is as follows:

Max (array1) = 9

Max (array2) = 18

Max (array1,) = 4

2

Ah

Range (0, 20, 3)

Bf3


Python standard library: Built-in Functions Max (iterable, *[, key, default])

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.