关键字:endwith、startwith
应用场景:endwith和startwith主要用于匹配字符串的开头或者结尾,一般用于判断文件类型等。
举例如下:将某个目录下的dll和ini文件筛选出来
import os
dlls = []
for item in os.listdir(r"C:MSP"):
if os.path.isfile(os.path.join(r"C:MSP", item)) and item.endswith((".dll", ".ini")):
dlls.append(item)
print(dlls)
"""
结果
['ACE.dll', 'avcodec-58.dll', 'avutil-56.dll', 'dcconf.ini', 'libeay32.dll', 'MSP_Config.ini', 'msvcp100.dll']
"""



