- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to find sum of elements in list
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given an list as an input, we need to compute the sum of the given list.
Here we have two approaches to consider i.e. using built-in function & using the brute-force approach.
Approach 1 − Using built-in function
Example
# main arr = [1,2,3,4,5] ans = sum(arr) print ('Sum of the array is ',ans)
Output
15
All the variables & functions are declared in the global scope and are shown below.
Approach 2 − Using brute-force method
Example
total = 0 # creating a list list1 =[1,2,3,4,5] for ele in range(0, len(list1)): total = total + list1[ele] # main print("Sum of all elements in given list: ", total)
Output
15
All the variables & functions are declared in the global scope and are shown below.
Conclusion
In this article, we learned about the approach to find the sum of the list.
- Related Articles
- Find sum of elements in list in Python program
- Program to find sum of odd elements from list in Python
- Program to find largest sum of non-adjacent elements of a list in Python
- Program to find sum of non-adjacent elements in a circular list in python
- Program to find sum of unique elements in Python
- Program to find maximum sum of popped k elements from a list of stacks in Python
- Python program to find Cumulative sum of a list
- Program to find three unique elements from list whose sum is closest to k Python
- Find sum of frequency of given elements in the list in Python
- Program to find sum of all elements of a tree in Python
- Python program to find Tuples with positive elements in List of tuples
- Program to find duplicate item from a list of elements in Python
- Program to find highest common factor of a list of elements in Python
- Program to find squared elements list in sorted order in Python
- Program to find only even indexed elements from list in Python

Advertisements