“缩进错误:unindent与任何外部缩进级别都不匹配”

时间:2013-09-15 20:42:50

标签: python

你可以告诉我这段代码有什么问题吗?

def insert_sequence(str1, str2, index):
    '''The first two parameters are DNA sequences and the third parameter
       is an index. Return the DNA sequence obtained by inserting the second
       DNA sequence into the first DNA sequence at the given index.

       >>>insert_sequence('CCGG', 'AT',2)
       CCATGG

    '''
   str1 = str1[0:index] + str2 + str1[index:len(str1)]
   return str1

2 个答案:

答案 0 :(得分:5)

您的docstring比函数体的其余部分缩进了一个空格。要么将文档限制在一个空格中,要么缩进剩下的一个空格(可能是后者,因为如果我算起来的话,那将使它成为四个空格)。

答案 1 :(得分:0)

Python对缩进非常严格,因此需要确保所有块都正确对齐,因此这里的问题是字符串比下面两行更远一个空格。让它们对齐,你应该很好。