一、提取字串操作——Python基礎
阿新 • • 發佈:2021-01-10
文章目錄
一、舉例字串
[email protected]:~# python3
>>> test = 'my apple'
>>> test
'my apple'
test中2代表空格
二、操作步驟
1.提取3以前的字元輸出
>>> test[:3]
'my '
2.提取3以後的字元輸出
>>> test[3:]
'apple'
3.提取3-7之間字元
>>> test[3:7]
'appl'
4.提取2字元(空格)
>>> test[2]
' '
5.提取所有字元
>>> test[:]
'my apple'
6.提取倒數第一個字元
>>> test[-1]
'e'
7.提取倒數5個以後的字元
>>> test[-5:]
'apple'
8.提取倒數5個以前的字元
>>> test[:-5]
'my '