Python Program to find Sum of Array
You are Here:
Find Sum of Array
In the following example, we will sum up all the elements (values) in an array (arr).
Example
Python Compiler
sum = 0
arr = [1, 2, 3, 4, 5]
for i in range(0, 5):
sum += arr[i]
print("Sum of array: %d" %sum)
Output
Sum of array: 15
Find Sum of any Given Elements in an Array
In the following example, we will sum up any given elements in an array.
Example
Python Compiler
sum = 0
arr = []
# number of elements as input
print("Enter any 5 (int) numbers: ")
# iterating till the range
for i in range(0, 5):
sum += int(input())
print("Sum of array: %d" % sum)
Output
Enter any 5 (int) numbers:
5
7
9
5
4
Sum of array: 30
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.
We are working to cover every Single Concept in Python.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.