**Python’s List Object type** is quite useful for storing data while dealing with Scientific Computations where large amount of data need to be processed. Anyway, in this article => I’ll discuss **How to find Maximum Number from a List of Numbers in Python?**

For finding maximum number out of all numbers in a Python List. Any of following three approaches can be used =>

- Sort Numbers in Ascending Order, then last number in List will be Maximum
- Using Python’s Built-in List Function –
**max()**, pass list to this function and it just returns Maximum Number in List - Loop through each element in List using
**For Loop**and compare individual numbers with**last seen Maximum Number**=> This approach is Worst performing as its making too much comparisons

Let’s discuss each one of these algorithmic approaches for **Finding Maximum Number in a Python List**.

Table of Contents

**Approach 1 => Find Maximum Number in a Python List**

- Define Python List
- Call
**sort() function**on list using**list_name.sort() statement** - Access last number in list using
**list_name[-1]** - Last Number in list will be Largest Number

```
# Python Program to Find largest number in List
a_list = [19, 82, 19, 17, -1, 2, -37] # Define List
a_list.sort() # Sort Nunbers in List in ascending order
print("Largest Number in List is => ", a_list[-1])
```

**Output of Above Code**

`Largest Number in List is => 82`

**Approach 2 => Find Largest Number in a Python List**

- Define Python List
- Pass list as parameter to
**max() function**using**max(list_name)**statement - Number returned by max() function would be largest in List

```
# Python Program to Find largest number in List
a_list = [19, 82, 19, 17, -1, 2, -37] # Define List
maximum_number = max(a_list) # Call max() function on List
print("Largest Number in List is => ", maximum_number)
```

**Output of Above Code**

`Largest Number in List is => 918`

**Approach 3 => Finding Maximum Number out of a Python List**

- Define Python List
- Assume first number in Python List to be Largest
- Loop over all numbers in List using
**for loop**and compare each number with the assumed maximum number, update assumed maximum number to current iteration number if its greater than assumed maximum number - At the end of
**For loop**return assumed maximum number

```
# Python program to find largest number in a list
a_list = [19, 38, 21, 34, 89] # Define Python List
def maximumNum(a_list):
# Assuming first number in list to be largest initially
# Assign it to variable "max"
max = a_list[0]
# Now traverse through the list using For Loop and compare
# each number with "max" value. Whichever number is
# largest assign that value to "max".
for x in a_list:
if x > max :
max = x
# after complete traversing the list
# return the "max" value
return max
print("Largest Number in List is => ", maximumNum(a_list))
```

**Output of Above Code**

`Largest Number in List is => 672`

## No Comments

Leave a comment Cancel