How to Use max() Function in PythonPython Basics


The max() method returns the maximum element from the given list.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print ("max(0, -100, -1000): ", max(0, -100, -1000))
print ("max(-20, 10, 40): ", max(-20, 10, 40))
print ("max(0.8, -2.0, -10): ", max(-0.8, -2.0, -10))
print ("max(-0.8965, -100, -200): ", max(-0.8965, -100, -200))

Output:

max(0, -100, -1000):  0
max(-20, 10, 40):  40
max(0.8, -2.0, -10):  -0.8
max(-0.8965, -100, -200):  -0.8965

Syntax

max(list)

Parameters

The parameter is the list from which max valued element to be returned.

Return Value

The method returns the largest element in the list.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us