Join Regular Classroom : Visit ClassroomTech

Python Tuple – sum() Method

It is a function in python that returns the Sum of the tuple. The tuple must contains numbers only and it returns a integer value.

Syntax:

sum(tuple, added)

Note: added is the value that is added to the sum of the tuple. By default it is 0.
Don’t know what is sorted method in Python Tuple? Read: Python Tuple – sorted() Method

Example 1:

# Python program to understand sum() method in tuple
# www.codewindow.in
s = (2, 8, 10)
x = sum(s)
print(x)

Output:

20

Explanation:

Here the sum of the numbers in the tuple is 20. Hence it returned 20.

Example 2:

# Python program to understand sum() method in tuple
# www.codewindow.in
s = (85, 55, 47, 98, 32, 65, 62, 54)
x = sum(s)
print(x)

Output:

498

Explanation:

Here the sum of all the numbers in the tuple is 498 . Hence it returned 498.


You Missed

Also Checkout