Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent use of tabs and spaces in indentation

def contains_sequence(dna1, dna2):
    ''' (str, str) -> bool

    Return True if and only if DNA sequence dna2 occurs in the DNA sequence
    dna1.

    >>> contains_sequence('ATCGGC', 'GG')
    True
    >>> contains_sequence('ATCGGC', 'GT')
    False

    '''
    b=False
    len2=len(dna2)
    i=0
    for j in dna1:
        temp=dna1[i:i+len2]
        if temp == dna2:
            b=True
        i=i+1
    return b

I am new to Python. The program pasted above gives me an error "Inconsistent use of tabs and spaces in indentation" at line "if temp == dna2:" specifically. Can someone please help me out in finding out how the indentation is incorrect?

like image 415
knightcool Avatar asked Oct 20 '12 14:10

knightcool


People also ask

How do you fix inconsistent use of tabs and spaces in indentation?

When the code is executed, the “TabError inconsistent use of tabs and spaces in indentation”. This occurs when the code has all the tabs and spaces mixed up. To fix this, you have to ensure that the code has even indentation. Another way to fix this error is by selecting the entire code by pressing Ctrl + A.

What does inconsistent indentation mean?

The Python “TabError: inconsistent use of tabs and spaces in indentation” error is raised when you try to indent code using both spaces and tabs. You fix this error by sticking to either spaces or tabs in a program and replacing any tabs or spaces that do not use your preferred method of indentation.

Should I use spaces or tabs for indentation?

It's not that tabs are completely bad but considering the vastness of the programming community and tools, spaces are a more standard and correct way to align and indent your code than tabs.


1 Answers

It means you have mixed up spaces and tabs in the indentation. You have to fix that to be consistent with either tabs or spaces.

like image 130
poke Avatar answered Sep 22 '22 04:09

poke