Python is a highly readable, less syntactic, interactive, object-oriented, interpreted, and high-level programming language. Python uses English terms instead of punctuation.

Some of the features of Python are mentioned below -

  • It can be used for production-ready applications or rapid prototyping as well.
  • It can handle complex computations and big data.
  • It uses simpler syntax and can be used to write complex codes in a shorter and simpler way.
  • Designed for readability and provides scope. It mainly relies on whitespace, indentation, etc.

In this article, we will discuss how to find the average of numbers present in the list in Python using the Average function in Python.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

Python Average

To find the average of given numbers in a list, we use the Python Average function. Average in Python is usually calculated by adding all the numbers in a list and then dividing it by the number of elements in this list.

There are multiple ways to find the average of a List in Python, and two of the main ways are mentioned below:

1) Python Average: Len() and Sum()

2) Python Average: statistics.mean()

1) Python Average: Len() and Sum()

The Sum() and Len() functions are built-in in Python and are used to find the averages. 

This method of finding the average helps avoid looping through the list and hence is time and effort-saving. This also reduces redundancy and helps maintain DRY code since it helps in finding the average of a list using a single line.

Example 1

numbers = [30, 55, 3, 10, 2]

average = sum(numbers)/len(numbers)

print("Average of list: ", round(average,3))

Output

Average of the list:  20.0

Example 2

num_list = [1, 999, 2, 1023, 223, 876, 32]

average = sum(num_list)/len(num_list)

print("Average of list: ", round(average,2))

Output

Average of the list:  450.86

Example 3 

numbers = [3098, 5565, 323, 1120, 2342, 75664]

average = sum(numbers)/len(numbers)

print("Average of list: ", round(average,1))

Output

Average of the list:  14685.3

Example 4 

numbers = [3, 55986365, 564323, 1314320, 72325342, 7534265664]

average = sum(numbers)/len(numbers)

print("Average of list: ", round(average,4))

Output

Average of the list:  1277409336.1667

Preparing Your Blockchain Career for 2024

Free Webinar | 5 Dec, Tuesday | 9 PM ISTRegister Now
Preparing Your Blockchain Career for 2024

2) Python Average: statistics.mean()

To easily calculate the python average of a list, we can use the statistics module’s mean() function. The following examples demonstrate the same.

Example 1 

from statistics import mean

num_list = [30, 55, 3, 10, 2]

average = mean(num_list)

print("Average: ", round(average,3))

Output

Average:  20

Example 2 

from statistics import mean

numbers = [1, 999, 2, 1023, 223, 876, 32]

average = mean(numbers)

print("Average: ", round(average,3))

Output

Average:  450.857

Example 3 

from statistics import mean

num_list = [3098, 5565, 323, 1120, 2342, 75664]

average = mean(num_list)

print("Average of list: ", round(average,1))

Output

Average of the list:  14685.3

Example 4 

from statistics import mean

num_list = [3, 55986365, 564323, 1314320, 72325342, 7534265664]

average = mean(num_list)

print("Average of list: ", round(average,4))

Output

Average of the list: 1277409336.1667

Choose The Right Software Development Program

This table compares various courses offered by Simplilearn, based on several key features and details. The table provides an overview of the courses' duration, skills you will learn, additional benefits, among other important factors, to help learners make an informed decision about which course best suits their needs.

Program Name Automation Testing Masters Program Full Stack Developer - MEAN Stack Caltech Coding Bootcamp
Geo All All US
University Simplilearn Simplilearn Caltech
Course Duration 11 Months 11 Months 6 Months
Coding Experience Required Basic Knowledge Basic Knowledge Basic Knowledge
Skills You Will Learn Java, AWS, API Testing, TDD, etc. HTML, CSS, Express.js, API Testing, etc. Java, JavaScript, Angular, MongoDB, etc.
Additional Benefits Structured Guidance
Learn From Experts
Hands-on Training
Blended Learning Program
Learn 20+ Tools and Skills
Industry Aligned Projects
Caltech Campus Connect
Career Services
17 CEU Credits
Cost $$ $$ $$$$
Explore Program Explore Program Explore Program

Master Python With Simplilearn!

To find the average of the numbers in a list in Python, we have multiple ways. The two main ways are using the Len() and Sum() in-built function and using the mean() function from the statistics module. In order to grasp Python concepts and dive deep into python development, we must consider resources that give us a complete insight into the topics with examples, activities, and exercises. 

Simplilearn provides such a comprehensive course through its Post Graduate Program in Full Stack Web Development. This course can help you hone the right skills and become job-ready in no time. 

If you have any questions, feel free to post them in the comments section below. Our team will get back to you at the earliest.

Our Software Development Courses Duration And Fees

Software Development Course typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Caltech Coding Bootcamp

Cohort Starts: 17 Jun, 2024

6 Months$ 8,000
Full Stack Developer - MERN Stack

Cohort Starts: 30 Apr, 2024

6 Months$ 1,449
Automation Test Engineer

Cohort Starts: 1 May, 2024

11 Months$ 1,499
Full Stack Java Developer

Cohort Starts: 14 May, 2024

6 Months$ 1,449