How to paste with correct indentation?

Asked

Viewed 29 times

0

It’s always a lot of work to fix indentation after copy and paste, but is there a way to paste with correct indentation? For example:

x = int(input("0 ou 1? "))
if x == 1:
    print("ON")                                                     
if x == 0:
    print("OFF")

After I changed my mind, I put while loop for example, I copied everything and pasted

Before:

while True:

After pasting:

while True:
    x = int(input("0 ou 1? "))
if x == 1:
    print("ON")                                                     
if x == 0:
    print("OFF")

Everything is wrong. It must be so:

while True:
    x = int(input("0 ou 1? "))
    if x == 1:
        print("ON")                                                     
    if x == 0:
        print("OFF")

Google Colaboratory has this feature to paste with indentation? And Visual Studio Code?

  • 3

    On several Ides, just mark the block after pasting it and press TAB

  • 1

    This will depend entirely on the tool you use to write code (IDE, text editor, ...).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.