sum()Easy Examples

Returns the total of all items in an iterable

Basic sum() usage

Simple demonstration of the sum() built-in function.

python
print(sum([1, 2, 3, 4, 5]))
print(sum(range(101)))
print(sum([0.1, 0.2, 0.3]))

sum() is a built-in function that returns the total of all items in an iterable.

sum() with different inputs

Calling sum() with various argument types.

python
# More sum() examples
print("sum() is a Python built-in function")
print(f"Type: {type(sum)}")

sum() accepts different types of arguments and produces corresponding results.

Want to try these examples interactively?

Open Easy Playground