“Jumlah daftar Python” Kode Jawaban

cara menghitung jumlah daftar dalam 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

Jumlah daftar Python

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

jumlah elemen dalam daftar.

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

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

Jumlah Daftar 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

Jumlah Isi Daftar 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

Jumlah daftar Python

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

Jawaban yang mirip dengan “Jumlah daftar Python”

Pertanyaan yang mirip dengan “Jumlah daftar Python”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya