How to Get the Largest Number in a List in Python


In this example we will show how to find the largest number in a given list with Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = input("Please input a list of numbers separated by SPACE: ")
a = n.split()
b = []
for i in a:
    b.append(int(i))
b.sort(reverse=True)
print("The largest number is:", b[0])

Output:

Please input a list of numbers separated by SPACE: 6 8 2 3 9 1 4 15
The largest number is: 15

Please input a list of numbers separated by SPACE: 16 12 18 13 19 23
The largest number is: 23 

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments