Get the App
SLTechnology News&Howtos  ›  Development  › 

Description and specific usage of python built-in function slice

Shulou Source: shulou.com Published: 2022-06-03 17:30:17 11月13日 Update

This article mainly explains "the explanation and specific use of python built-in function slice". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn the "python built-in function slice instructions and specific use of it" bar!

Description:

1. Function is actually a constructor of a sliced class that returns a sliced object.

two。 The slice object consists of three attributes: start, stop, and step. The default values of start and step are None. The slice object is mainly used to slice the sequence object to get the corresponding elements.

> > help (slice) class slice (object) | slice (stop) | slice (start, stop [, step]) | | Create a slice object. This is used for extended slicing (e.g. A [0:10:2]). | | Methods defined here: | |. # omitted # |-| Data descriptors defined here: | | start | | step | | stop | |-| -| Data and other attributes defined here: | | _ _ hash__ = None > a = list (range (10)) > a [0] 1, 2, 3, 4, 5, 6, 7, 8, 9] > > a [None:5:None] # start step is explicitly None [0,1,2,3,4] > > a [: 5:] # start step defaults to None [0,1,2,3,4] > > a [2:5:None] # step is explicitly None [2,3,4] > > a [2:5:] # step defaults to None [2,3,4] > > a [1:10:3] [1,4] 7]

3. The three attributes start, stop and step,slice of the corresponding slice object also have three corresponding parameters start, stop and step, and their values are paid to the start, stop and step of the slice object, respectively.

> > C1 = slice (5) # definition C1 > c1slice (None, 5, None) > c2 = slice (2meme 5) # definition c2 > > c2slice (2penny 5, None) > c3 = slice (1recorder 10pas 3) # Definitions c3 > > c3slice (1mie 10fui 3) > a [C1] # and a [: 5:] have the same result [0,1,2,3,4] > > a [c2] # and a [2:5] have the same result [2,3] 4] > a [c3] # and a [1:10:3] results are the same [1,4,7] so far I believe that everyone on the "python built-in function slice description and specific use of" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Functions objects methods usage same results content actual attributes learning practical deeper elements interests parameters practicality actually sequence simple operation more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Huawei Redmi Apple