How to sum in python

coldplay.xixi
Release: 2023-01-03 09:28:05
Original
21710 people have browsed it

The method of summing in python: use sum syntax to sum [sum(iterable[, start])], where iterable is an iterable object and start is a parameter that specifies addition. If this is not set value, default is 0.

How to sum in python

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

How to sum in python:

1. Sum usage syntax

sum(iterable[, start])
Copy after login
  • iterable -- Iterable objects, such as lists, tuples, and sets.

  • start -- Specify the parameters for addition. If this value is not set, it defaults to 0.

2. Examples of using sum

For example: the result of sum([1,2,3]) is 6

sum((2, 3, 4), 1) The result of is 10, which means that 1 is added after summing the tuples.

sum([0,1 ,2,3,4], 2) The result of is 12, which means adding 2 after summing the list.

How to sum in python

Related free learning recommendations :python video tutorial

The above is the detailed content of How to sum in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template