擅长:python、mysql、java
<p>这将打印句子编号(0索引)。</p>
<pre><code>with open("sample.txt") as f:
content = f.read() # Read the whole file
lines = content.split('.') # a list of all sentences
for num,line in enumerate(lines): # for each sentence
if 'word' in line:
print(num)
else:
print("Not present")
</code></pre>