Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create the sequence type range of python

Shulou Source: shulou.com Published: 2022-06-02 02:26:18 09月21日 Update

Most people do not understand the knowledge points of this article "how to create the sequence type of python range", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to create the sequence type of python range" article.

Sequence types (including lists, etc.) can use the operators in and not in to check whether the specified integer exists in the sequence of integers represented by the range object, 3 in range (5) checks whether it contains 3, and returns True

You can call the built-in function range (the constructor of class range) to create objects of type range

Range (stop)

Range (start, stop)

Range (start, stop, step)

The default value of the starting value of the integer sequence is 0, which can be specified using the parameter start

Use the parameter stop to specify the end value of the sequence; the rang object created does not contain stop

The default step size of an integer sequence is 1, which can be specified using the parameter step

The return value of the built-in function range is an iterator object, which can be converted into a list in order to clearly represent the sequence of integers represented by the returned iterator object

The advantage of the range type is that no matter how long the sequence of integers represented by range objects, all range objects occupy the same memory space, and only three parameters of start,stop,step need to be stored. It is only when the range object is used that you go back to calculate the relevant elements in the sequence

Range (5) # range (0,5)

List (range (5)) # converts range type objects to lists [0,1,2,3,4]

List (range (0,5,1)) # [0,1,2,3,4]

List (range (1,5)) # [1,2,3,4]

List (range (1d10, 2)) # [1, 3, 5, 7, 9]

List (range (0,-10,-2)) # [0,-2,-4,-6,-8]

Help (range) for more descriptions of range

The above is about the content of this article on "how to create the sequence type of python range". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Sequence object type integer content parameter function article more knowledge article check iteration clarity same three value advantage element memory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB Shulou Technology Redmi Apple