首 页 行业热点 新车 试驾评测 养车用车 车型库

python 判断字符串是否循环

发布网友

我来回答

1个回答

热心网友

executeRecord="niu"
rec = open('py.txt', 'r+')
lineInfos = rec.readlines()
recordFlag = True
for row in lineInfos:
print(row.strip().find(executeRecord))
# find函数-1表示找不到匹配内容,其他输出结果为找到的索引值
if row.strip().find(executeRecord) != -1:
print("%s 已经存在!" % (executeRecord))
# 记录过即不再记录
recordFlag = False
break
if recordFlag:
executeRecord = '%s\n' % executeRecord
rec.write(executeRecord)
rec.close()

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com