Max() function of list in Python

Overview:

  • The max() function returns the maximum of the elements present in a Python list.

Example:

# Example Python program that creates
# list of floating point numbers and 
# prints the largest of them

# List creation
floats = [1.1, 0.9, 0.6, 1.5, 0.8, 0.2]

print("Floating point numbers from the list:")
print(floats)

print("The largest floating point number in the list:")
print(max(floats))

Output:

Floating point numbers from the list:

[1.1, 0.9, 0.6, 1.5, 0.8, 0.2]

The largest floating point number in the list:

1.5

 


Copyright 2024 © pythontic.com