python判断字符串是否以某个子字符串开头或结尾
startswith() 方法用于检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False。
endswith() 方法用于检查字符串是否是以指定子字符串结尾,如果是则返回 True,否则返回 False。可以用来判断文件的扩展名
用法:
s = 'CIDC-A-a17b95c1db9b4a8d9c8791525a0e649d'
if s.startswith('CIDC-A'):
print(s.startswith('CIDC-A'))
打印True