Error in range() function – Python 3.11.3

I’m new in programming and I’m facing an error in Python that I didn’t find a way to correct.

I’m trying to use the function range(). According to documentation if I try the follow command it should print as follows:

[1, 2, 3, 4]

However when I execute it in console or in a script .py the output is as follows:

range(0, 4)

I tried to find something online without success. I check the documentation, used ‘help(range)’ and it should work according to the documentation and examples I saw online. I tried also console, pycharm, visual studio, always the same.

>Solution :

print(range(4)) prints a range object.

You should print:


#[1, 2, 3, 4]

Just to make you understand;

if you put range in set you will get:

#{0, 1, 2, 3}

If you put range in tuple you will get:

#(0, 1, 2, 3)

Similarly, if you put range in list you will get:

#[0, 1, 2, 3]

Link to doc:

Leave a Reply