“Python Sum of List” Código de respuesta

Cómo calcular la suma de una lista en Python

# Python code to demonstrate the working of  
# sum() 
numbers = [1,2,3,4,5,1,4,5] 
  
# start parameter is not provided 
Sum = sum(numbers) 
print(Sum) # result is 25  
# start = 10 
Sum = sum(numbers, 10) 
print(Sum) # result is 10 +25 = 35
Quaint Quail

Python Sum of List

>>> list = [1, 2, 3]
>>> sum(list)
6
Kodi4444

Suma de elementos en una lista.

data = ['5', '4', '9']

sum(int(i) for i in data)
18
Smiling Shrike

Suma de la lista de Python

To get the sum of a list in python, you just call the built in sum() function.
An example:

>>> lst = [3, 7, 1, 9, 4]
>>> sum(lst)
24
Blue Justice

suma el contenido de una lista de python

# Sum the contents of a list without the builtin sum function

list = [1,2,3,4,5]
sum = 0

# loop through each position of the list and 
# add the contents of each position to the variable, sum
for i in range(len(list)):
	sum += list[i]

# result is 1 + 2 + 3 + 4 + 5 = 15
print(sum)
liamxaro

Lista de resumen Python

b = [1,2,3]
a = sum(b)
# 6
Cloudy Caterpillar

Respuestas similares a “Python Sum of List”

Preguntas similares a “Python Sum of List”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código