Skip to content

Python program to find a maximum and minimum number in a list | Code

  • by

Use max() and min() functions to find a maximum and minimum number in a list in Python. This methods are return the maximum and minimum of the list, respectively.

Python program to find a maximum and minimum number in a list example

Simple example code.

a_list = [5, 2, 7, 6, 3, 1, 0]

maximum = max(a_list)

print("Max", maximum)

minimum = min(a_list)

print("Min", minimum)

Output:

Python program to find a maximum and minimum number in a list

Another way

Python Program to find the Largest and Smallest Number in a List using the sort() method.

a_list = [5, 2, 7, 6, 3, 1, 0]

a_list.sort()

print("Max", a_list[-1])
print("Min", a_list[0])

Output:

Max 7
Min 0

Do comment if you have any doubts or suggestions on this Python program.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading