python 字符串匹配

参考:https://www.jianshu.com/p/c555113a30ea

简单的,则使用下面方法

filenames.startswith('file')  #True
filenames.endswith('.txt')

s.find("ok") #存在则返回下标,否则返回-1


(复杂的建议使用正则匹配式re) 

col_names = df_train.columns.values.tolist()
k = []
for i in col_names:
    if(i.endswith(("cat","bin"))):
        k.append(i)

 

 
posted @ 2020-12-14 18:20  qiezi_online  阅读(162)  评论(0编辑  收藏  举报