Here we use 2 predefined functions min() and max() which check for the smallest and largest number in a list respectively.
Master the basics of data analysis in Python. Expand your skillset by learning scientific computing with numpy.Ad:Limited time sale - 50% OFF Learn in-demand data and AI skills on the 17th of July
You can watch the video on YouTube here
Largest and Smallest in a list – Code Visualization
To find the largest and smallest number in a list.
- Read the input number asking for the length of the list using
- Initialize an empty list
lst = .
- Read each number using a
- In the for loop append each item to the list,
- Now we use a predefined function
max()to find the largest element in a list.
- Similarly, we use another predefined function
min()to find the smallest element in a list.
lst =  num = int(input('How many numbers: ')) for n in range(num): numbers = int(input('Enter number ')) lst.append(numbers) print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is :", min(lst))
That is for the post, here I have found the largest and the smallest element in a given list, using
min() built-in functions of the list which give us the maximum and minimum element from a given list.
Want to learn Python with strong fundamentals? If yes, I strongly suggest you take the course below.
Course: Fundamentals of Programming in Python