Python Program to find Sum of Array

Last Updated:

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)

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)

Share this Page

Meet the Author