English documents:
-
range
(
stop)
-
range
(
start,
stop[,
step])
-
Rather than being a function, is
range
actually an immutable sequence type, as documented in Ranges and sequence Types -list, tuple, range.
Description
-
1. The range function is used to generate a Range object, and the range type is a type that represents an integer range.
-
2. You can directly pass in an end integer to initialize a range type with a default starting value of 0 (inclusive of 0). The ending integer can be greater than 0 or less than or equal to 0, but a Range object that is less than or equal to 0 does not actually contain any elements.
>>> A = range (5)>>>5)>>> Len (a)for in A:print(x) 0# incoming 0, empty Range object >>> len (b) 0>>> C = Range ( -5) # incoming negative number, empty Range object >>> len (c) 0
3. You can pass in a starting integer and an end integer to initialize a range type that contains all integers between the starting integer (inclusive) and the ending integer (not included).
>>> a = range (1,5)>>> arange (1, 5) for in a:print (x)1234
4. The starting and ending integers are passed in, and you can pass in a step value at the same time to initialize a range type, which contains the starting integer (inclusive), and the integer filtered by the stepping value between the ending Integer (contains).
>>> a = range (1,10,3)>>> arange (1, ten, 3) for in a: Print (x)147
5. Initializes the range type with the starting and ending integers, followed by the left arm right-opening principle, which contains the starting integer, but not the ending integer.
>>> a = range (1,5)>>> arange (1, 5 for in a:print # contains 1, does not contain 51234
6. Range receives parameters that must be integers and cannot be other data types such as floating-point numbers.
>>> A = range (3.5) Traceback (most recent): File"<pyshell#33>", Line 1,inch<module>a= Range (3.5) TypeError:'float'object cannot is interpreted as an integer>>> A = range ('3.5') Traceback (most recent): File"<pyshell#34>", Line 1,inch<module>a= Range ('3.5') TypeError:'Str'Object cannot is interpreted as an integer
7. Range is actually an immutable sequence type that can take elements, slices, and so on, but cannot modify values on the elements.
>>> a = range (1,5)# take element # Slice range (1, 3)# Modify element value Traceback (most recent call last): "<pyshell#38>" in <module> a[1] = 2'range'not Support Item Assignment
-
Python built-in function (--range)