SoFunction
Updated on 2024-11-16

Summary of fast ways to indent multiple lines of code in python programs

Indentation is the essence of the language. Indentation allows you to indicate the scope of program structures such as functions and loops. Sometimes after writing a program, you find that all the procedures need to be put into the function def, then you need to indent a whole program at the same time, and there are other cases, you may also need to indent multiple lines as a whole. Here is how to realize multi-line indentation under the official IDLE editor.

Introduced here is for version 3.0 and above, the software comes with an editor, the whole indentation method. First of all, through the start menu , find IDLE, click to start the software.

1561195653(1).png

Related: "Python video tutorials

After launching the software, open an already built or newly created program file through the file menu, under the Open or New option, where a new program is created.

1561195566(1).png

The newly created program is shown in the following figure, at this time you need to show all the programs, into the function named calcu under the contents of all programs need to increase the indentation once.

1561195576(1).png

Increase def that is, after the function definition statement, you need to move the contents of the red box in the figure below to the right as a whole once the amount of shrinkage (generally four bytes), if it is not too much trouble, you can be in the red box in the contents of each line are added to the four spaces, but this method is more laborious.

1561195586(1).png

The following is a quick way to achieve whole block indentation, first select all the parts of the program to be indented, here select def statement below, all the parts as function content.

1561195596(1).png

At this time, first press and hold down the "shift" key, and then press the "tab" key, remember to press only once, to immediately release. At this point, as shown in Figure 1 below, to complete the indentation once. If you press and hold, or press the key combination several times, it will be indented several times, as shown in Figure 2 below, for the effect of multiple indentation. So for version 3.0 and above, the software comes with a program editor, how to achieve multi-line indentation, the introduction is complete.

1561195605(1).png

1561195614(1).png