In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces what the python string conversion function, 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.
1. Replace replaces the old character / string in the original string with the specified new string.
# a.replace () # replaces the old character / string in the original string with the given new string (but does not modify the original string itself) msg = 'The day is a sunny day'result1 = msg.replace (' day','DAY') # replaces the previous parameters with the latter parameters. The default is to replace all the previous parameters with the latter parameters. The default is to replace all the previous parameters with the latter parameters. Replace twice print (result2) result3 = msg.replace ('axiajiaozhongjie 1) # replace the previous parameter with the latter parameter, and replace the print (result3) once output: The DAY is a sunny DAYThe d | y is | sunny dayThe dAy is a sunny day
2. Capitalize changes the first letter of a string to capitalization.
Just change the first letter of the entire string to uppercase, not the first letter of each substring in the string to uppercase.
# a.capitalize () changes the first letter of the string to uppercase (but does not modify the original string itself) s = 'jack tom's_new = s.capitalize () print (s_new) output: Jack tom
3. The first letter of each word in the title uppercase string.
# a.title () # uppercase s = 'good day's1 =' good day-sz*sz2--qq%yy' # of each word in the string is bounded by a delimiter (those that are not letters in the middle are converted to uppercase) s_new = s.title () s1_new = s1.title () print () print (s1_new) output: Good DayGood Day-Sz*Sz2--Qq%Yy
4. Lower lowercase all the characters in the string.
# a.lower () # lowercase every character in the string, the same as casefold (). S = 'Good Day HA's_new = s.lower () print (s_new) output: good day ha thanks you for reading this article carefully. I hope the article "what is the function of python to convert strings" shared by the editor will be helpful to you. At the same time, I hope you will support it 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.