E114 indentation is not a multiple of four (error) in python

An indentation error in Python occurs when the code is not properly aligned according to Python's indentation rules. Python uses indentation to define the structure of the code, such as blocks within loops, functions, conditionals, etc. Here are common causes and how to fix them:

Common Causes of Indentation Errors:

  1. Inconsistent Indentation: Mixing tabs and spaces.
  2. Incorrect Block Indentation: Indenting the code block incorrectly relative to its control structure (e.g., a loop or function).
  3. Unintentional Indentation: Accidentally adding extra spaces or tabs.


(E114) This error is raised when comment line has indentation which is not multiple of four.

Example 1:

def say_hello():
    plainText = "hello!"

     # TxtText:markdown = "hello!"  (this is wrong, it uses 5 spaces before comment)

    # TxtText:markdown = "hello!"   (this is right, it uses 4 spaces before comment)


Example 2:

(Incorrect)
def example_function():
print("This will cause an indentation error")


(Correct)
def example_function():
    print("This is correctly indented")


How to Fix Indentation Errors:

  1. Check for Consistent Indentation: Make sure you are using either spaces or tabs consistently throughout your code. The Python style guide (PEP 8) recommends using 4 spaces per indentation level.

  2. Use an IDE/Text Editor: Most modern IDEs or text editors like PyCharm, VS Code, or Sublime Text automatically handle indentation and highlight issues.

  3. Re-indent the Code: If the code block is misaligned, re-indent it to match the expected structure.

  4. Convert Tabs to Spaces: If you've mixed tabs and spaces, convert them to spaces. Many text editors have an option to convert tabs to spaces.


Comments

Popular posts from this blog

Setting up a USB thermal printer with a Raspberry Pi 3B+

Autostart an app on reboot - Raspberry Pi

Basic Input/Output C Program