“somme python de la liste” Réponses codées

Comment calculer la somme d'une liste dans 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

somme python de la liste

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

somme d'éléments dans une liste.

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

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

Somme de liste 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

résume le contenu d'une liste 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

résumer la liste Python

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

Réponses similaires à “somme python de la liste”

Questions similaires à “somme python de la liste”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code