好吧,我有关于以下代码的问题:
s = "wxyabcd"
myString = s[0]
longest = s[0]
for i in range(1, len(s)):
if s[i] >= myString[-1]:
myString += s[i]
if len(myString) > len(longest):
longest = myString
else:
myString = s[i]
print longest
回答:“abcd” w wx公司 wxy公司 一 ab型 abc公司 abcd
我是Python新手,我正试图了解其中一些循环是如何工作的,但我很困惑。这找到了字母顺序中最长的字符串。。。实际的答案是“abcd”,但我知道它经历的过程是一个接一个的。在
问题:有人能帮我看完代码吗?这样我就能更好地理解它了吗?因为有7个字符,我假设它的开头是:“对于1-7范围内的每一个项目,如果这个项目是'more'而不是myString[-1],也就是'w',那么我加上字母加上I中的项目,在这个例子中它是'x'。在
在这之后我就迷路了。。。那么从a-z:a>;z?是这样吗?那么当s[i]!=myString[-1]是否跳过从s[i]中的“a”开始。在
对不起,我到处都是。不管怎样,我试着在网上搜索一些地方来帮助我学习这些,但是有些事情很难做到。我知道几个月后我就会掌握窍门,希望能说得更流利。在
谢谢你!在
下面是对控制流的一点解释,以及Python索引的原理,希望能有所帮助:
我能想到的两种方法(快速)
相关问题 更多 >
编程相关推荐