In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the python slice and indices function how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
In general, the built-in slice () function creates a sliced object that can be used anywhere slicing is allowed.
Here is a brief introduction to slice:
# two uses of slice: class slice (stop) class slice (start, stop [, step])
Returns a slice object that represents the index set specified by range (start, stop, step). The parameters start and step default to None. The slice object has read-only data properties start, stop, and step that only return the corresponding parameter values (or their default values). They have no other explicit functionality; however, they will be used by NumPy and other third-party extensions.
Sliced objects are also generated when extended index syntax is used. For example: a [start:stop:step] or a [start:stop, I].
See itertools.islice () for an alternative version of the iterator returned.
Items = [0,1,2,3,4,5,6] a = slice (2pyr4) print (items [2:4]) # [2,3] items [a] # [2:3] items [a] = [10,11] print (items) # [0,1,10,11,4,5,6] del items [a] # [0,1,4,5,6]
If you have an instance of a slice object, you can get information about that object through the s.atart, s.stop, and s.step properties, respectively. Example:
A = slice (10,50,2) print (a.start) # 10print (a.stop) # 50print (a.step) # 2
Here is the official explanation of indices:
Slice.indices (self, length)
This method takes an integer parameter length and calculates how the information about the slice should be described when the slice object is applied to a sequence of items of a specified length in length. The return value is a tuple of three integers; these numbers are the start and stop index numbers of the slice and the step step value, respectively. If the index number is missing or out of bounds, it is handled in the way of regular serial slices.
All values have been properly limited within boundaries (IndexError exceptions can be avoided when indexing) example:
S = 'HelloWorld'a.indices (len (s)) # (5,10,2) for i in range (* a.indices (len (s): print (s [I]) # w# r # d Thank you for reading this article carefully. I hope the article "how to use slice and indices functions in python" shared by the editor will be helpful to you. At the same time, I hope you will support and pay attention to the industry information channel. More related knowledge is waiting for you 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.