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=[[]]*3
a[1].append(7)
print(a)

a.

Syntax error

b.

[[7], [7], [7]].

c.

[[7], [], []].

d.

[[],7, [], []].

Posted under Lists in Python Python

Answer: (b).[[7], [7], [7]].

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?