adplus-dvertising
frame-decoration

Question

What is the output of the following code?
a=[1,2,3,4]
b=[sum(a[0:x+1]) for x in range(0,len(a))]
print(b)

a.

10

b.

[1,3,5,7].

c.

4

d.

[1,3,6,10].

Posted under Python

Answer: (d).[1,3,6,10].

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the following code?