I was trying different ways of using the range()
function in Python and when I tried this:
print(range(1, 20, 2), end=" ")
I got an output like this: range(1, 20, 2 )
, when I was expecting something like this: 1 3 5 7 9 11 13 15 17 19
Why is this the case?
Also, are there any other ways to print a range of numbers other than using a loop statement, or is it compulsory to always use loops if I want a sequence of numbers using range()
?