0
Why does print(range(3,8)) doens't prints 3,4,5,6,7 and prints range(3,8) , I haven't marked any quotation then also đ.
Range -- Python
6 Respostas
+ 11
In order to output the range as a list, we need to explicitly convert it to a list, using the list() function.
Aman sharma I think no, we can't :(
print(list(range(3,8)))
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2434/
+ 4
#You can use Unpacking operator *
print(*range(3,8))
#output : 3 4 5 6 7
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-kwargs-and-args/#:~:text=In%20short%2C%20the%20unpacking%20operators,only%20be%20used%20on%20dictionaries.
+ 1
Thanks simba , but I came from this lesson only đ I just wanted to know what about the quotations to print strings as it printed range(3,8) as if it's a string
+ 1
that's because since python3 range objects are generators: it consume ressources only when using it as iterating (basically it just store the arguments to defer/postpone the computation at time of use it...)
so, once you have iterated once, it cannot be iterated again (it is consumed)... and you probably don't want that if you log it ^^
however, you can consume it and store the result to be iterared again: that doesn't make big time difference in your script, only require more memory (as opposite if you use it only once, memory requirement is limited to one value at a time).
0
Can't it simply just output that without conversion
0
Thanks ratan , can you give me the link of lesson in which we can learn about these operators đ