欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python字符串大小寫轉(zhuǎn)換拼接刪除空白

 更新時(shí)間:2019年09月19日 15:06:20   作者:歲月不負(fù)人  
這篇文章主要介紹了Python字符串大小寫轉(zhuǎn)換拼接刪除空白的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1.字符串大小寫轉(zhuǎn)換

  • string.title() #將字符串中所有單詞的首字母以大寫形式顯示
  • string.upper() #將字符串中所有字母轉(zhuǎn)化為大寫字母
  • string.lower() #將字符串中所有字母轉(zhuǎn)化為小寫字母
str = "hello world!"
print(str.title())
Hello World!
print(str.upper())
HELLO WORLD!
print(str.lower())
hello world!

2.字符拼接

python中只用使用'+'便可以進(jìn)行字符串拼接

str1 = 'Hello'
str2 = 'World'
print(str1+str2)
HelloWorld
str3 = str1+str2
print(str3)
HelloWorld

3.刪除空白

string.lstrip() #刪除串首的空白
string.rstrip() #刪除串尾的空白
string.strip() #刪除左右量表的空白

strip的意思就是剝奪,所以lstrip()就是剝奪left_strip,剝除左邊的數(shù)組即串首的空白

str = ' Hello Beijing '
print(str.lstrip())
print(str.rstrip())
print(str.strip())
Hello Beijing 
 Hello Beijing
Hello Beijing

總結(jié)

以上所述是小編給大家介紹的Python字符串大小寫轉(zhuǎn)換拼接刪除空白,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評論