In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Python how to carry out Slicing Lists and Strings slicing operation, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Learn the Lists and Strings slicing operations of python today.
Create a new python file named py3_slicing.py, and write the operation code in this file:
# define a listnumlist = [0,1,2,3,4,5,6,7,8,9]
# forward index 0, 1, 2, 3, 4, 5, 6, 7, 8, reverse index-10 fuzuki 9 meme 8 lime8 lime7 lime6 lime5 lime4 lime3 Muimei 2 Lai 1
# print the value of the first index location print (numlist [0]) # 0
# print the value of the last index location print (numlist [- 1]) # 9
# print the value of the first index location print (numlist [- 10]) # 0
# list [start:end:step] # specify the start start position of the shard
# end end position
# step step size (spacing)
# print values from 0 to 4 for index positions # the parameters here were mentioned before 0:5 in the article # left open and right closed: including left excluding right [0Magne5) print (numlist [0:5])
# [0,1,2,3,4] # print values of index positions 0 to 5 print (numlist [0:6]) # [0,1,2,3,4,5] # print values print of index positions 3 to 7 (numlist [3:8])
# [3, 4, 5, 6, 7] # print the values of the index position-7 to-3 print (numlist [- 7 print]) # [3, 4, 5, 6, 7]
# print values from index position 1 to-3 print (numlist [1:-2])
# [1, 2, 3, 4, 5, 6, 7] # print the value print from index position 1 to list end position (numlist [1:])
# [1,2,3,4,5,6,7] # print the value print from index position 5 to the end position of list (numList [5:])
# [5, 6, 7 minus 8] # print the values from list start index position 0 to index-2 print (numlist [:-1]) # [0, 1, 2, 3, 4, 5, 6, 7, 8]
# print the entire listprint (numlist [:]) # print the value of the index position 2 to-2 in 2print (numlist [2:-1:2]) # [2, 4, 6, 8]
# print the value of the index position from 2 to-1 in steps of-empty listprint (numList [2:-1]) # [] # when the step size is negative, the slicing operation is
# reverse access to the elements in the list from right to left
# regardless of whether the step step size is positive or negative
# the begin and end index values of the slicing expression # need to ensure that there are elements between # begin and end in the access direction of the slicing operation, so that the slicing operation can ensure that a non-empty set is returned.
# numlist = [0,1,2,3,4,5,6,7,8,9]
# forward index 0,1,2,3,4,5,6,7,8,9
# reverse indexing-10 meme 9 limel 8 lime7 lime6 lime5 lime4 lime3 lime2 lime1
# as can be seen from the comments above, numlist [2] accesses the list list from right to left. # the valid index interval from right to left can be (2mai Murlen (numlist)-1).
# understanding-slice-notation print (numlist [1::-1]) # [1, 0] print (numlist [- 1 numlist 2 numlist 1]) # [9, 8, 7, 6, 5, 4, 3] print (numlist [- 1 numlist 2 numlist 1])
# [9, 8, 7, 6, 5, 4, 3] print (numlist [- 1 print 2)) # [9, 7, 5, 6, 5, 4, 3, 2, 1, 0]
# Strings slicing Operation Learning python_url = 'https://www.python.org'
# reverse urlprint (python_url [::-1])
# gro.nohtyp.www//:sptth# obtains the domain domain name print (python_url [- 4:])
#. Org # get the domain name print (python_ URL [12:-4]) # python
Running effect:
090 [0, 1, 2, 3, 4] [0, 1, 2, 3, 4, 5] [3, 4, 5, 6, 7] [3, 4, 5, 6, 7] [1, 2, 3, 4, 5, 6, 7] [1, 2, 3, 4, 5, 6, 7, 8, 9] [5, 6, 7, 8, 9] [0, 1, 2, 3, 4, 5, 6, 7, 8] [0, 1, 2, 3, 4, 5, 6, 7, 8 9] [2, 4, 6, 8] [1, 0] [9, 8, 7, 6, 5, 4, 3] [9, 8, 7, 6, 5, 4, 3] [9, 7, 5, 3] [9, 8, 7, 6, 5, 4, 4, 3, 2, 1, 0] is it helpful for gro.nohtyp.www//:sptth.orgpython to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.