0

I am new to python and i'm following this tutorial but im getting this error. There's an error in your program:

unindent does not match any outer indentation level

This is the code.

def Xero():
    print 'Here is some content!'
    print 'And some more...!'
    for i in xrange(5):
        print 'Hello!'
Xero()
Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67

3 Answers3

2

This happens when you have mixed tabs and spaces in your code. Use only spaces or tabs, but don't mix between the two.

The recommendation is to use spaces.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
1

This is a common error when dealing with spaces. You probably have an extra space before Xero(), or some of your print statements have mixed tabs/spaces before them. I generally find that in order to get the spacing right, I copy all of the whitespace from before the first argument, and paste it on all the lines after. It might help to use an IDE such as spyder to avoid problems like this.

P.S. - Since you're new to python, you should try Python 3.

Riet
  • 1,240
  • 1
  • 15
  • 28
0

Follow PEP 8 for Python style. PEP 8 says: Indentation

Use 4 spaces per indentation level.

For really old code that you don't want to mess up, you can continue to use 8-space tabs

Tabs or Spaces?

Never mix tabs and spaces.

The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. Code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. When invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

Sakib Ahammed
  • 2,452
  • 2
  • 25
  • 29