【发布时间】:2020-08-02 19:13:56
【问题描述】:
我很确定我的程序还有另一个愚蠢的错误,但我找不到。 google了一阵子,还是没有结果。
我正在尝试使用 len 方法进行循环。我在程序中的不同函数中以完全相同的方式使用它没有问题,但在这个函数中我得到一个 TypeError:
def longestPalindrome(DNA):
"""
Finds the longest palindrome in a piece of DNA.
"""
DNA = DNA.upper #makes sure DNA is in all caps
longest = ""
for x in range(len(DNA)):
for y in range(len(DNA)):
long = DNA[x:y+1]
if checkPalindrome(long) and (len(long) > len(longest)):
longest = long
return longest
DNA 是一个字符串,而 checkPalindrome 是一个较早的函数,用于检查一段 DNA 是否为回文。
【问题讨论】:
标签: python typeerror string-length