Python standard library: built-in function max (iterable, * [, key, default]), pythoniterable

Source: Internet
Author: User

Python standard library: built-in function max (iterable, * [, key, default]), pythoniterable

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

This function is an iteration object iterable to compare and find the maximum value to return. When the key parameter is not null, the function object of the key is used as the criterion for determination.

Example:

# Max () array1 = range (10) array2 = range (0, 20, 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) print (max ('Ah', 'bf', key = lambda x: x [1]) print (max (array1, array2, key = lambda x: x [1]) def comparator (x): return x [2] print (max ('ah2', 'bf3', key = comparator ))

The output is as follows:

Max (array1) = 9

Max (array2) = 18

Max (array1,) = 4

2

Ah

Range (0, 20, 3)

Bf3

 


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.