+ 4

Adding numbers in a list. Python

Python. Suppose A is a list. There are some numbers in A. I want to add all those numbers together. But how? Pls help.

1st Oct 2019, 8:41 AM
Ishraq Chy
Ishraq Chy - avatar
7 Respuestas
+ 4
sum([1,2,3,4,5])
1st Oct 2019, 9:15 AM
Trigger
Trigger - avatar
+ 4
Use sum function sum(A) or use the following: _sum = 0 for i in A: _sum += 1 print(_sum)
2nd Oct 2019, 6:03 PM
Pradip Thoyal
Pradip Thoyal - avatar
+ 3
It can be done by two ways: M1- using predefined function. A=[] Print(sum(A)) M2- creating a program. A=[] Sum=0 for num in A: Sum+= num #add each num after num print(sum)
2nd Oct 2019, 7:22 AM
namrata garg
namrata garg - avatar
1st Oct 2019, 10:57 AM
Faisal
0
sum(A)
3rd Oct 2019, 4:55 AM
Matthew Li
Matthew Li - avatar