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)
Python Program to find the Largest and Smallest Number in a List using sort() method.
a_list = [5, 2, 7, 6, 3, 1, 0] a_list.sort() print("Max", a_list[-1]) print("Min", a_list)
Do comment if you have any doubts or suggestions on this Python program.
Note: IDE: PyCharm 2021.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.