溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

[python]字符串總結(jié)

發(fā)布時間:2020-06-03 19:07:13 來源:網(wǎng)絡(luò) 閱讀:271 作者:望天兒先生 欄目:編程語言

1
message1="I love you ,China!"
print(message1)
message2="wO aI ni zhong guo"
print(message2.title()) ##首字母大寫
print(message2.upper()) ##字符串全部大寫
print(message2.lower()) ##字符串全部小寫
message3=message1.title()+" "+message2.upper() ##字符串拼接
print(message3)

2
print("\tleslie") ##/t制表符
print("language:\nchinese\nenglish\njanpanese") ##換行符
print("language:\n\tchinese\t\nenglish\n\tjanpanese") ##制表符和換行符混用

3
favorite_language = ' python '
favorite_language
favorite_language.rstrip() ##刪除結(jié)尾空白
favorite_language
favorite_language.lstrip() ##刪除開頭空白
favorite_language
favorite_language.strip() ##刪除字符串開頭和結(jié)尾空白

4
name1=input("name1:")
print("hello "+name1+",would you like to learn some python today?")

5
name1=input("name1:")
print(name1.lower())
print(name1.upper())
print(name1.title())

6
print('Albert Einstein once said,"A person who never made a mistake never tried anything new."')

7
famous_person = input("famous_person:") ##輸入一個變量
print(famous_person.title()+' once said,"A person who never made a mistake never tried anything new."')

8
famous_person = "\txu\nlijian\thaha\nhaha\t"
print(famous_person)
print(famous_person.lstrip()) ##刪除開頭空格
print(famous_person.rstrip()) ##刪除結(jié)尾空格
print(famous_person.strip()) ##刪除開頭和結(jié)尾空格
print(famous_person.replace('\n','').replace('\t','')) ##連續(xù)替換\n和\t為空

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI