Python 字串處理

2022-08-24 06:03:13 字數 1053 閱讀 2014

1 單引號包圍的字串中可以包含雙引號,同樣,雙引號包圍的字串中可以包含單引號

2 三個引號包圍的字串中既可以包含單引號,也可以包含雙引號

message = "

father's day

"print

(message)

message = '

mother"s day

'print

(message)

message = '''

有"雙引號"也有'單引號'哦

'''print(message)

3 首字母大寫

message = "

father's day

"print(message.title())

4 全部大寫

message = "

father's day

"print(message.upper())

5 全部小寫

message = "

father's day

"print(message.lower())

6 拼接字串

message = "

father's day

"print(message + "

" + "

!")

7 製表符(\t),換行符(\n)

message = "

"print(message)

8 刪除空白

message = "

test.

"print

(message.lstrip())

print

(message.rstrip())

print(message.strip())

9 轉換成字串

message = 3

print(str(message) + "

years ago

")

Python 字串處理

python endswith 方法用於判斷字串是否以指定字尾結尾,如果以指定字尾結尾返回 true 否則返回 false 可選引數 start 與 end 為檢索字串的開始與結束位置。語法 endswith 方法語法 str.endswith suffix start end 引數 返回值 如果字...

Python字串處理

去空格及特殊符號 s.strip lstrip rstrip 複製字串 strcpy sstr1,sstr2 sstr1 strcpy sstr2 sstr1 sstr1 strcpy2 print sstr2連線字串 strcat sstr1,sstr2 sstr1 strcat sstr1 ss...

Python字串處理

python字串處理 part i 常見處理函式 string.find sub,start 0,end len string 檢測sub是否包含在string中,如果是返回 第乙個sub 開始的索引值,否則返回 1.string.index sub,start 0,end len string 跟...