skip to Main Content

When I try to run my code in REPL, it indents every line automatically. I don’t know what causes it to indent every line. I have showed an example below. As you can see my code is right, but indention makes it fail.

enter image description here

I have reinstalled VS Code and Python many times, but there is no fix.

2

Answers


  1. Indent is necessary in python, its not js or cpp that you define the code that will be executed if the condition is true in {}, here indented code is just like code in curly brackets in other languages. If you want to write something out of the condition, just press the backspace.
    NOTE: vscode automatically indent after you write loop of conditional statement etc.
    See here

    Login or Signup to reply.
  2. When you copied the Python code, the characters are inserted where the cursor is.

    The REPL indents automatically for human typists to save them typing spaces. And then the copied code inserts the additional spaces.

    The solution is to avoid this way of to run your code. Instead, save the file and run that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search