Home > Backend Development > Python Tutorial > What does python range mean?

What does python range mean?

爱喝马黛茶的安东尼
Release: 2019-06-20 11:54:05
Original
7688 people have browsed it

Detailed usage of python range() function

Function prototype: range(start, end, scan):

Parameter meaning: start: counting starts from start. The default is to start from 0. For example, range (5) is equivalent to range (0, 5);

end: counting to the end of end, but not including end. For example: range (0, 5) is [0, 1, 2, 3 , 4] No 5

scan: The distance between each jump, the default is 1. For example: range(0, 5) is equivalent to range(0, 5, 1)

What does python range mean?

##Basic usage example:

Python
>>> for i in range(1,5):   
print(i)
1
2
3
4
>>> for i in range(5):    
print(i)
0
1
2
3
4
>>> for i in range(0,5,2):    
print(i)
0
2
4
>>> for i in range(0,-5,-2):
print(i)
0
-2
-4
Copy after login

Related recommendations:《

Python video tutorial

Note:

The difference between python2 and python3:

python3 returns an iteration value:

Python3

print(range(1,5))
range(1, 5)
# 正确打印方法
list(range(1,5))
[1, 2, 3, 4]
Copy after login

python2 returns a list:


Python2

>>> range(1,5)
[1, 2, 3, 4]
Copy after login

The above is the detailed content of What does python range mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template