lstrip&rstrip
s='khffhksfksf'
print(s.lstrip('kn'))
print(s.rstrip('sf'))
hffhksfksf
khffhksfk
lower&upper
print(s.upper())
KHFFHKSFKSF
startswith&edndswith
print(s.startswith('1'))
print(s.startswith('k'))
print(s.startswith('f',2,3))#表示索引2到索引3,当前为f
False
True
True
rsplit
name='halfh:af jd:afl'
print(name.rsplit(':'))
print(name.split(':'))
print(name.split(':',1))
print(name.rsplit(':',1))
['halfh', 'af jd', 'afl']
['halfh', 'af jd', 'afl']
['halfh', 'af jd:afl']
['halfh:af jd', 'afl']
join
name_list=['dhskdbll','ffskf','ffskf','shfk']
print(name_list)
print('sd'.join(name_list))#用sd连接起来
['dhskdbll', 'ffskf', 'ffskf', 'shfk']
dhskdbllsdffskfsdffskfsdshfk
replace
name1='aflffskff4ffskf'
print(name1)
print(name1.replace('afl','dhj'))
print(name1.replace('ffskf','l',1))
print(name1.replace('ffskf','l'))
aflffskff4ffskf
dhjffskff4ffskf
afllf4ffskf
afllf4l
isdigit
print(name.isdigit())
print('140'.isdigit())#判断140是否为只包含数字字符
False
True