Is the sequence of numbers generated by the range() function a tuple?

Question:

On an online course, the teacher says that range() produces a tuple, adding that this is the reason why we have to convert it into a list (thanks to the list() function) if we want to modify it.

Is this statement true ?

Because in the official documentation, they dont talk about tuple at all in the range() section : https://docs.python.org/3/tutorial/controlflow.html#the-range-function

Asked By: PhpDoe

||

Answers:

Starting with python3, range returns a range object which is a sequence type which, among other things, can be iterated to create a list out of it.

Relevant docs about the range type.

Before that, it used to return a list, like Klaus commented. (docs)

Answered By: EDG956
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.