---
title: "How to find the maximum and minimum values in a list using Python?"  
description: "How to find the maximum and minimum values in a list using Python?"  
author: "Steilla Mitchel"  
published: 2023-07-04  
updated: 2023-07-05  
canonical: https://www.mindstick.com/forum/158958/how-to-find-the-maximum-and-minimum-values-in-a-list-using-python  
category: "python"  
tags: ["python", "list"]  
reading_time: 3 minutes  

---

# How to find the maximum and minimum values in a list using Python?

How to find the [maximum and minimum values](https://www.mindstick.com/forum/158868/how-do-you-find-the-maximum-and-minimum-values-in-a-list-in-python) in a list using [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)?

## Replies

### Reply by Aryan Kumar

Sure, there are a few ways to find the maximum and minimum [values](https://www.mindstick.com/forum/327/sum-textbox-values) in a list using Python. Here are a few examples:

**Using the** `max()` **and** `min()` **functions:**

The `max()` and `min()` functions are built-in functions in Python that can be used to find the maximum and minimum values in a list. The `max()` function takes a list as input and returns the largest value in the list. The `min()` function takes a list as input and returns the smallest value in the list.

For example, the following code will find the maximum and minimum values in the list `list1`:

Python

```plaintext
list1 = [10, 4, 2, 9, 7, 5, 3, 8, 6]
max_value = max(list1)
min_value = min(list1)
print("The maximum value is", max_value)
print("The minimum value is", min_value)
```

The output of the code is:

Code snippet

```plaintext
The maximum value is 10
The minimum value is 2
```

## Using a for loop:

You can also use a for loop to find the maximum and minimum values in a list. The basic idea is to iterate over the list, keeping track of the largest and smallest values that you have seen so far.

For example, the following code will find the maximum and minimum values in the list `list1`:

Python

```plaintext
list1 = [10, 4, 2, 9, 7, 5, 3, 8, 6]
max_value = list1[0]
min_value = list1[0]
for i in range(1, len(list1)):
  if list1[i] > max_value:
    max_value = list1[i]
  elif list1[i] < min_value:
    min_value = list1[i]
print("The maximum value is", max_value)
print("The minimum value is", min_value)
```

The output of the code is the same as the previous example.

**Using the** `enumerate()` **function:**

The `enumerate()` function in Python can be used to iterate over a list and get the index of each element. This can be useful for finding the maximum and minimum values in a list, because you can use the index to keep track of which element is the largest and smallest so far.

For example, the following code will find the maximum and minimum values in the list `list1`:

Python

```plaintext
list1 = [10, 4, 2, 9, 7, 5, 3, 8, 6]
max_value = list1[0]
min_value = list1[0]
for i, value in enumerate(list1):
  if value > max_value:
    max_value = value
  elif value < min_value:
    min_value = value
print("The maximum value is", max_value)
print("The minimum value is", min_value)
```

The output of the code is the same as the previous two examples.


---

Original Source: https://www.mindstick.com/forum/158958/how-to-find-the-maximum-and-minimum-values-in-a-list-using-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
