In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you the "python string concatenation. Join () and split. Split () function", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "string concatenation. Join () and split. Split () function in python" this article.
1. String split function .split ()
Split the string by space:
S = "fd as sf" res = s.split ("") print (res)
The returned value is: ['fd','as','sf']
Note:
S.split ("") is often used to split words in a sentence.
The return value after split is of type list!
two。 String concatenation function .join ()
Concatenate strings by spaces (which can be any character):
L = ['1century print 12 minutes'] res = ".join (l) print (res)
The returned result is:'1 12 s'
Note:
The returned value after stitching is of type str!
Extension: understand ".join (s.split (") [::-1]) [::-1] s = "I love you" res = ".join (s.split (") [::-1]) [::-1] print (res)
The return value is "I evol uoy"
Analysis:
The meaning of this sentence is that, given a string, you need to reverse the character order of each word in the string, while still retaining the initial order of spaces and words.
This sentence deducts the solution of question 557: 557. Reversing the word III in a string
In addition to the above .join () and .split (), it also involves the use of python slices.
Readers can understand for themselves (or see the official analysis) the meaning of this sentence.
Note: for more information on the parsing of python slices, please see Bowen: detailed explanation of Python slicing operation
The following is a partial excerpt:
A complete slice expression contains two ":" to separate three parameters (start_index, end_index, step). When there is only one ":", the default third parameter, step=1;, when there is no ":", start_index=end_index, indicates that the element specified by start_index is cut.
Basic expression of slicing operation: object [start _ index:end_index:step]
Step: both positive and negative numbers are available, and their absolute values determine the''step size' when fetching data, while a positive or negative sign determines the "cutting direction", with a positive value "from left to right" and a negative value "from right to left". When step is omitted, the default is 1, that is, the value is taken by step 1 from left to right. " It is very important to take direction! " It is very important to take direction! " It's very important to cut the direction! "say the important things three times!
Start_index: represents the starting index (including the corresponding value of the index); when this parameter is omitted, it means that the value starts from the "endpoint" of the object, and whether to start from the "starting point" or from the "end point" is determined by the positive or negative of the step parameter. Step is positive from the "starting point" and negative from the "end point".
End_index: indicates the termination of the index (excluding the corresponding value of the index); when this parameter is omitted, it means that it is taken all the way to the "endpoint" of the data, and whether it is to the "starting point" or to the "end point" is also determined by the positive or negative of the step parameter. Step is positive until the "end point" and negative until the "starting point".
These are all the contents of the article "string concatenation in python. Join () and split. Split () function". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.