Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
for index, line in enumerate(open('text.txt', 'r'), start=1):
if 'word' in line:
print(index, line.strip())
break
text= open('text.txt', 'r')
line = text.readline()
i=0
while line:
print (line),
if line=='word':
ns=i
break
line = text.readline()
i+=1
text.close()
print ('Номер нужной строки ',ns)
text= open('text.txt', 'r')
for id, line in enumerate(text.readlines()):
print (line)
if line=='word':
break
text.close()
print ('Номер нужной строки ',id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question