Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python | Find missing elements in List
Next article icon

Find sum of elements in List – Python

Last Updated : 05 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Finding the sum of elements in a list means adding all the values together to get a single total. For example, given a list like [10, 20, 30, 40, 50], you might want to calculate the total sum, which is 150. Let’s explore these different methods to do this efficiently.

Using sum()

sum() function is the most efficient way to calculate the sum of all elements in a list. It automatically takes care of iterating over the list and summing up the values for you.

Python
a = [10, 20, 30, 40, 50] res = sum(a) print(res) 

Output
150 

Explanation: sum() function adds all the numbers in the list a and stores the result in res.

Using for loop

For loop gives you more control over the process. By manually iterating over the list, you can accumulate the sum step by step.

Python
a = [10, 20, 30, 40, 50] res = 0 # Initialize sum variable  for i in a:     res += i  print(res) 

Output
150 

Explanation: For loop iterates through each element in the list, adding it to res in each step until all elements are summed.

Using list comprehension

List comprehension allows you to create a new list based on an existing one and then use sum() to calculate the total. This is a more Pythonic way to do things when you want to transform the list first.

Python
a = [10, 20, 30, 40, 50]  res = sum([i for i in a]) print(res) 

Output
150 

Explanation: List comprehension creates a new list identical to a and the sum() function then calculates the total of its elements, storing the result in res.

Using reduce()

reduce() function from the functools module applies a function (in this case, addition) to the elements of the list cumulatively. This method is less commonly used but provides a functional programming style solution.

Python
from functools import reduce a = [10, 20, 30, 40, 50]  res = reduce(lambda x, y: x + y, a) print(res) 

Output
150 

Explanation: reduce() function uses the lambda to cumulatively add pairs of elements from left to right, resulting in the total sum stored in res.

Related articles

  • sum()
  • For loop
  • List comprehension
  • reduce()


Next Article
Python | Find missing elements in List

S

Shivam_k
Improve
Article Tags :
  • DSA
  • Python
  • Python Programs
  • School Programming
  • Python list-programs
  • python-list
Practice Tags :
  • python
  • python-list

Similar Reads

  • Python program to find sum of elements in list
    Finding the sum of elements in a list means adding all the values together to get a single total. For example, given a list like [10, 20, 30, 40, 50], you might want to calculate the total sum, which is 150. Let's explore these different methods to do this efficiently. Using sum()sum() function is t
    3 min read
  • Python | Find missing elements in List
    Sometimes, we can get elements in range as input but some values are missing in otherwise consecutive range. We might have a use case in which we need to get all the missing elements. Let's discuss certain ways in which this can be done. Method #1 : Using list comprehension We can perform the task o
    7 min read
  • Python | Find common elements in list of lists
    The problem of finding the common elements in list of 2 lists is quite a common problem and can be dealt with ease and also has been discussed before many times. But sometimes, we require to find the elements that are in common from N lists. Let's discuss certain ways in which this operation can be
    6 min read
  • Python - Elements Lengths in List
    Sometimes, while working with Python lists, can have problem in which we need to count the sizes of elements that are part of lists. This is because list can allow different element types to be its members. This kind of problem can have application in many domains such has day-day programming and we
    6 min read
  • Find Index of Element in Array - Python
    In Python, arrays are used to store multiple values in a single variable, similar to lists but they offer a more compact and efficient way to store data when we need to handle homogeneous data types . While lists are flexible, arrays are ideal when we want better memory efficiency or need to perform
    2 min read
  • Python - Negative index of Element in List
    We are given a list we need to find the negative index of that element. For example, we are having a list li = [10, 20, 30, 40, 50] and the given element is 30 we need to fin the negative index of it so that given output should be -3. Using index()index() method in Python searches for the first occu
    3 min read
  • Find an Element In a List of Tuples
    In Python programming, it is often necessary to locate an element inside a list of tuples. Tuples are arranged collections, and locating a particular piece inside them requires knowledge of a variety of strategies. When data is kept as tuples inside a list, this procedure is essential for data retri
    3 min read
  • Python | Remove given element from list of lists
    The deletion of elementary elements from list has been dealt with many times, but sometimes rather than having just a one list, we have list of list where we need to perform this particular task. Having shorthands to perform this particular task can help. Let's discuss certain ways to perform this p
    6 min read
  • Get the Last Element of List in Python
    In this article, we will learn about different ways of getting the last element of a list in Python. For example, consider a list: Input: list = [1, 3, 34, 12, 6]Output: 6 Explanation: Last element of the list l in the above example is 6. Let's explore various methods of doing it in Python: 1. Using
    2 min read
  • Python - Odd elements indices
    Sometimes, while working with Python lists, we can have a problem in which we wish to find Odd elements. This task can occur in many domains such as web development and while working with Databases. We might sometimes, require to just find the indices of them. Let’s discuss certain way to find indic
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences