Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Description and specific usage of python built-in function slice

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report