In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to name slices in python. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Name slice object
The commonly used slicing method is to use the index to control the beginning and end. As follows:
1record = '.170.60.'
2print (f "height {record [20:23]}, weight {record [31:33]}") # height 170, weight 60
Because we use index numbers to control slices, this makes the code difficult to read and only see the numeric subscript. So to make the code easier to read, we can use sliced objects and the slice () function:
1record = '.170.60.'
2print (f "height {record [20:23]}, weight {record [31:33]}") # height 170, weight 60
3height = slice (205.23)
4weight = slice (31 cam 33)
5print ("height {}, weight {}" .format (recordheight, weight))
Above, slice (start, stop, step) is used to generate sliced objects and assign variables. Variable slicing objects make the code easier to understand. Readers do not have to pay attention to the location of the source string corresponding to the index when they read the code again. This way of naming sliced objects is easier to read.
The parameter step refers to the step size.
Generally speaking, if a large number of hard-coded subscript values appear in the code, the readability and maintainability will be greatly reduced. For example, if you look back at the code you wrote a year ago, you will touch your head and wonder what you wanted to do at that time. The solution here is a very simple way for you to express more clearly what the code is going to do. The built-in slice () function creates a slice object that can be used wherever slices are allowed. For example:
1items = ["h",'e-maths, girls, girls, boys, girls, girls
2a = slice (2pc7)
3print (items [a]) # = = items [2:7]
4items [a] = "12345" # string assignment, slice is a string
5print (items)
6items [a] = ['axiomagy'] # list element assignment, slice is a tuple
7print (items)
eight
Slicing object
10a = slice (1, 1010, 2) # start, end,step
11print (items [a])
12print (a. Print. A. Stop. Step) # start1 10 2
The above is how to name slices in python. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.