Home>Article>Backend Development> The difference between range function python2 and 3
The range function is a general function used to create arithmetic series sequences, returning an integer sequence of [start, start step, start 2 * step, ...] structure;
Range() function usage in py2:(Recommended learning:Python video tutorial)
range() return is a list
>>> list=range(10) >>> print list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
The range() function usage in py3:
range() function returns an iterable object ( The type is object), not a list type, so the list will not be printed when printing.
list() function is an object iterator, converting the object into a list. The returned variable type is a list.
>>> range(10) range(0, 10) >>> type(range(10))>>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> type(list(range(10)))
For more Python-related technical articles, please visit thePython Tutorialcolumn to learn!
The above is the detailed content of The difference between range function python2 and 3. For more information, please follow other related articles on the PHP Chinese website!