python學習筆記(六)--正則表達式

1.正則表達式中最常見的符號和字符



2.正則常用的函數和方法


3.其他

line.startswith('python') 

line[:-1].endswith('a')

例:def find_file(fname):
    f=open(fname)
    for line in f:
        if line.startswith('python') and line[:-1].endswith('a'):
            print (line)
find_file("E://Python//p.txt")

def find_file(fname):
    f=open(fname)
    for line in f:
        if line.startswith('python') and line.endswith('a\n'):
            print (line)
find_file("E://Python//p.txt")





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章