Python

Python Menu

Python

Python sum() Function - Definition, Syntax, Parameters, Examples

Definition

The sum() function returns a number, the sum of all items in an iterable.

Syntax

sum(iterable, start)

Parameters

Parameter Description
iterable Required. The sequence to sum
start Optional. A value that is added to the return value

Examples

# starts at 0 and adds the numbers from the sequence myNumbers = (1, 2, 3, 4, 5) result = sum(myNumbers, 0) print(result)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods