Home>Article>Backend Development> The difference between range function python2 and 3

The difference between range function python2 and 3

(*-*)浩
(*-*)浩 Original
2019-07-05 10:36:25 3389browse

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;

The difference between range function python2 and 3

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn