Two solutions here.
To remove the last 4 characters in general:
s = 'this is a string1234'
s = s[:-4]
yields
'this is a string'
And more specifically geared toward filenames, consider os.path.splitext() meant for splitting a filename into its base and extension:
import os
s = "Forest.bmp"
base, ext = os.path.splitext(s)
results in:
print base
'Forest'
print ext
'.bmp'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…