Javatpoint Logo
Javatpoint Logo

Python sum() Function

As the name says, python sum() function is used to get the sum of numbers of an iterable, i.e. list.

Signature

sum(iterable, start)

Parameters

iterable - iterable can be list, tuples, and dictionaries, but an iterable object must contain numbers.

start - The start is added to the sum of numbers in the iterable. If start is not given in the syntax, it is assumed to be 0.

Let's see some examples of sum() function are given below:

Python sum() Function Example 1

This example shows sum of the list of numbers:

Output:

5
15

Python sum() Function Example 2

This example shows sum of floating point numbers:

Output:

7.0

Python sum() Function Example 3

This example shows sum of complex numbers:

Output:

(4+6j)
(6+8j)
(4.5+0j)






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA