擅长:python、mysql、java
<p>您可以使用以下代码:</p>
<pre><code>s = 'abcdefgahijkblmnopqrstcuvwxyz'
sub = ''
test = s[0]
for index, character in enumerate(s):
if index > 0:
if character > s[index - 1]:
test += character
else:
test = character
if len(test) > len(sub):
sub = test
print 'Longest substring in alphabetic order is: ' + str(sub)
</code></pre>
<p>还有几点建议。在</p>
<ol>
<li>Python字符串是iterable。i、 你可以在它们之间循环。在</li>
<li>当您希望在迭代列表的索引时使用enumerate。在</li>
</ol>