特定字符串替换
t='2018-08-07'
t1=t.replace('-','')
print(t1) #输出为20180807
字符串截取与拼接
path='E:/项目/Djangocode/RSMDSys/static/imagedata/1535974092.287188.jpg'
path1=path.split('/')
print('path1:',path1)
path2=path.split('/',4)
print('path2:',path2)
print('type(path2):',type(path2))
path3=path2[-1]
print('path3:',path3)
path4='/'+path3
print('path4:',path4)
#运行结果
path1: ['E:', '项目', 'Djangocode', 'RSMDSys', 'static', 'imagedata', '1535974092.287188.jpg']
path2: ['E:', '项目', 'Djangocode', 'RSMDSys', 'static/imagedata/1535974092.287188.jpg']
type(path2):
path3: static/imagedata/1535974092.287188.jpg
path4: /static/imagedata/1535974092.287188.jpg