Reputation: 39
I want to print all elements as a list. I have included the current and expected outputs.
for i in range(0,3):
P=i
print(P)
The current output is
0
1
2
The expected output is
[0,1,2]
Upvotes: 0
Views: 42
Reputation: 36
l = list() # create an empty list
for i in range(0,3):
l.append(i) # append the list with current iterating index
print(type(l)) # <class'list'>
print(l)
Upvotes: 2
Reputation: 81
Convert the range
to list and print it.
elems = list(range(0,3))
print(elems)
Upvotes: 0