Why am I getting an indentation error?



Why am I getting an indentation error?


If you’re seeing an error message that says something about an IndentationError it means you have code that isn’t indented properly somewhere. Remember, Python uses indentation (2 spaces per indentation on Codecademy) to determine blocks of code.
If you’ve written a return statement outside of a function (not indented inside to be inside the function), that will give you this error. For example:

def my_function():
  print "Hello!"
return 0  # This is a return outside of any function!

FAQ: Learn Python – Lists and Functions – Using an element from a list in a function