[Python] Why do I get errors using shift-enter to run Python code in my IDE?

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use Python (2.17.15 via Anaconda) on Visual Studio Code on my Mac. I have the following simple code:

    def function(x):
    y = x + 2
    return y



    This code is giving me an indentation error:

    return y
    ^
    IndentationError: unexpected indent
    >>> return y
    File "<stdin>", line 1
    return y
    ^
    IndentationError: unexpected indent
    >>>


    Needless to say that Jupyter or Spyder have no problem with this. I checked that on VSC tab gives 4 spaces. All similar questions are related to this, but I cannot fix it.

    Other, built in functions of Python work fine.

    Please give me some help or tips since I do not know how to escape this.

    Installing again Python3 this simple code DOES work on Sublime but still not on VS Code. I still get the same error in VS Code.

    If I change from return to print and instead of shift-command debug and run the code then it works.

    Any idea what is going on?

    Continue reading...

Compartilhe esta Página