strip()和split()
strip() 方法
用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列。
该方法只能删除开头或是结尾的字符,不能删除中间部分的字符。
str1 = "0000000123456Awin_Ge3456700000000000" #######去除首尾字符0#######
print str1.strip('0') #######去除首尾字符0#######
输出
123456Awin_Ge34567
str2 = " Awin_Ge "
print str2.strip()
输出
Awin_Ge
str3 = "1234Awin_Ge4321"
print str3.strip('123')
输出
4Awin_Ge4
split()
通过指定分隔符对字符串进行分割并返回一个列表,默认分隔符为所有空字符,包括空格、换行(\n)、制表符(\t)等
str4 = "This is string example!!!!!!!"
print str4.split()
print str4.split('i',1)
print str4.split('!')
['This', 'is', 'string', 'example!!!!!!!']
['Th', 's is string example!!!!!!!']
['This is string example', '', '', '', '', '', '', '']