{"id":24847,"date":"2021-11-02T09:54:35","date_gmt":"2021-11-02T04:24:35","guid":{"rendered":"https:\/\/python-programs.com\/?p=24847"},"modified":"2021-11-02T09:54:35","modified_gmt":"2021-11-02T04:24:35","slug":"python-sum-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-sum-function-with-examples\/","title":{"rendered":"Python sum() Function with Examples"},"content":{"rendered":"

sum() Function in Python:<\/strong><\/p>\n

The sum() function returns a number that represents the sum of all items in an iterable.<\/p>\n

Syntax:<\/strong><\/p>\n

sum(iterable, start)<\/pre>\n

Parameters<\/strong><\/p>\n

iterable<\/strong>: This is required. It is the sequence\u00a0 to be sumed.<\/p>\n

start<\/strong>: This is optional. It is a value added to the return value. The value of start is 0 by default (if omitted)<\/p>\n

Return Value:<\/strong><\/p>\n

sum() returns the sum of the iterable’s start and items.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [1, 2, 6, 15, 5]<\/pre>\n

Output:<\/strong><\/p>\n

The sum of all the items in a given list = 29<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [1, 2, 3, 5, 10]\r\nstart value = 4<\/pre>\n

Output:<\/strong><\/p>\n

The sum of all the items in a given list with given start value =  25<\/pre>\n

sum() Function with Examples in Python<\/h2>\n