name = ‘xiaoming.li‘
tr = "Line1-abcdef \nLine2-abc \nLine4-abcd";
print str.split(); # 以空格为分隔符,包含 \n
print str.split(‘ ‘, 1 ); # 以空格为分隔符,分隔成两个
结果:
[‘Line1-abcdef‘, ‘Line2-abc‘, ‘Line4-abcd‘]
[‘Line1-abcdef‘, ‘\nLine2-abc \nLine4-abcd‘]
str1 = "00003210Runoob012300000";
print(str1.strip(‘0‘));# 去除首尾字符0
结果:3210Runoob0123
str2 = " Runoob "; #去除首位空格
print(str2.strip())
结果:Runoob
str3 = ‘123adc123121‘
print(str3.strip(‘12‘))# 去除首尾字符序列12
结果:3abc123
tr = "this is string example....wow!!!";
print (str.startswith( ‘this‘ ))
print (str.startswith( ‘is‘, 2, 4 ))
print (str.startswith( ‘this‘, 2, 4 ))
结果:True、True、False
原文:https://www.cnblogs.com/shukeshu/p/11330095.html