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)05/31 Report--
This article mainly introduces the "Python string letter case conversion method". In the daily operation, I believe that many people have doubts about the Python string letter case conversion method. The editor consulted all kinds of data and sorted out a simple and easy operation method. I hope it will be helpful to answer the doubts of "Python string letter case conversion method". Next, please follow the editor to study!
1.lower ()
Convert uppercase letters in a string to lowercase letters
Syntax: str.lower ()
# example: str1 = "LiBai is a boy" str2 = "WWW.jrcg.com" print (strl) print ("after conversion:", str1.lower ()) print (str2) print ("after conversion:", str2.lower ())
Running result:
LiBai is a boy
After conversion: libai is a boy
WWW.jrcg.com
After conversion: www.jrcg.com
2.upper ()
Convert lowercase letters of a string to uppercase letters
Syntax: str.upper ()
Str1 = "www.libai.com" print (str1) print ("after conversion:", str1.upper ())
Running result:
Www.libai.com
After conversion: WWW.LIBAI.COM
3.capitalize ()
Make the first letter of the string uppercase and the rest lowercase.
Syntax: str.capitalize ()
Strl = "happy new year" print (strl.capitalize ())
Running result:
Happy new year
4.title ()
Returns a string that satisfies the title format, that is, the first letters of all English words are capitalized and the rest of the letters are lowercase.
Syntax: str.title ()
Str3 = "i love Python" print (str3.title ())
Running result:
I Love Python
5.swapcase ()
Interchange the uppercase and lowercase letters in the string str at the same time, that is, convert the uppercase letters in the string str to lowercase letters and convert lowercase letters to uppercase letters.
Syntax: str.swapcase ()
Str3 = "jingRUOchENguang" print (str3.swapcase)
Running result:
Running result: JINGruoCHenGUANG
6.casefold ()
Converts all uppercase letters in a string to lowercase letters. You can also convert uppercase to lowercase in non-English languages.
The difference between the # lower () function and the casefold () function: the lower () method is only encoded for ASCII, that is, it works for Amurz, and it is not valid for other languages to convert uppercase to lowercase. You can only use the casefold () function.
At this point, the study on the "Python string letter case conversion method" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.