擅长:python、mysql、java
<p>三件事。首先,在函数中,您可能打算使用以下结构<code>break</code>。你知道吗</p>
<pre><code>for char in sequence:
if char == start:
startCount += 1
else:
break
for char in reversed(sequence):
if char == end:
endCount += 1
else:
break
</code></pre>
<p>其次,在文件中循环行时,不需要使用<code>str</code>函数将行转换为字符串。它们已经是弦了!你知道吗</p>
<p>第三,行包括换行符,它们是这样的:<code>'\n'</code>它们用来告诉计算机何时结束一行,何时开始一行。要除去它们,可以使用string的<code>rstrip</code>方法,如下所示:</p>
<pre><code>file = open("Test.txt", 'r')
for line in file:
a,b = getStartEnd(line.rstrip())
print a, b
file.close()
</code></pre>