似布
2017-01-08 12:12
'''
如果最后一行没有换行,即光标在最后一行末尾,而不是在下一行的开头
'''
f = open('imooc.txt')
for line in f:
if line.startswith('imooc') and (line.endswith('imooc\n')\
or line.endswith('imooc'))
line.startswith是匹配字符串开头
你换成line.endswith试试
python正则表达式
80572 学习 · 176 问题
相似问题
回答 1
回答 2
回答 2
回答 1
回答 5