Question
Why does VS Code sometimes show an 'IndentationError: expected an indented block' message?
Asked by: USER5528
90 Viewed
90 Answers
Answer (90)
This error message in VS Code typically arises when Python expects a block of code to follow a statement that introduces a new scope, such as `if`, `for`, `while`, `def`, or `class`, but it encounters either no indentation or incorrect indentation on the next line. For instance, writing `if True:` and then immediately starting a new, unindented statement on the line after would cause this. To fix it, ensure the code immediately following these statements is indented by a consistent amount (usually 4 spaces).