0

print(range(4))

The Above one has supposed to print the range of 4, that means, [0, 1, 2, 3] but the output is printing (0, 4) why?

22nd Jul 2020, 5:10 AM
Mr. 12
Mr. 12 - avatar
4 Antworten
+ 6
Mr. 12 Another one-liner 😃 print([*range(4)])
22nd Jul 2020, 5:46 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
+ 5
It prints "range(0, 4)", which is the standard representation of "range instance". If you want all the elements within be printed, you can try any of the followings: r=range(4) print(list(r)) print(*r) print([ i for i in r ])
22nd Jul 2020, 5:20 AM
李立威
+ 3
Mr. 12 the method you tried will work in python 2.x, in python 3 this is removed and you have to use list() function to generate list...
22nd Jul 2020, 8:42 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
0
李立威 thank you bro
22nd Jul 2020, 5:26 AM
Mr. 12
Mr. 12 - avatar