In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail the methods of removing spaces from common strings in Python. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1:strip () method
Remove the space at the beginning or end of the string
> a = "a b c" > a.strip () 'a b c'2:lstrip () method
Remove the space at the beginning of the string
> a = "a b c" > a.lstrip ()'a b c '3:rstrip () method
Remove the space at the end of the string
A: there are no answers to problems encountered in study. The editor has created a Python learning exchange group: 531509025 look for like-minded partners to help each other, and there are also good video learning tutorials and PDF e-books in the group! > a = "a b c" > a.rstrip () 'a b c'4:replace () method
All spaces can be removed.
Replace is mainly used to replace replace (old, new, count) of strings.
> a = "abc" > > a.replace (",") 'abc'5: join () method + split () method
All spaces can be removed.
Join passes in a list of strings for character string synthesis. Split is used for string segmentation and can be divided according to rules.
> a = "a b c" > b = a.split () # string is divided into lists by spaces > b ['asides,' b' 'c'] > c = ".join (b) # compose list contents with an empty string to generate a new string > c 'abc' # shortcut usage > a =" abc ">" .join (a.split ())' abc' about what are the common methods for removing spaces in Python? Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
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.