Home > Article > Backend Development > How to quickly indent multiple lines of code in python program
Indentation is the essence of this language. Indentation can indicate the scope of program structures such as functions and loops. Sometimes after writing a program, it is found that all the programs need to be put into function def. In this case, the entire program needs to be indented at the same time. In other cases, multiple lines of the entire program may also need to be indented. The following describes how to achieve overall multi-line indentation in the official IDLE editor.
What is introduced here is for version 3.0 and above, the software comes with its own editor and the method of indenting the whole block. First, find IDLE through the start menu and click to start the software.
Related recommendations: "Python Video Tutorial"
After starting the software, open or create a new option under the file menu. An already built or newly created program file, create a new program here.
The newly created program is as shown in the figure below. At this time, all the programs shown in the picture need to be placed under the function named calcu, and all program contents need to be indented once.
After adding def, which is the function definition statement, you need to move the entire content in the red box in the picture below to the right by a reduction amount (usually four bytes). If you don’t mind Trouble, you can add four spaces to each line of content in the red box, but this method is more troublesome.
The following introduces how to quickly implement the indentation of the entire block. First, select all the program parts to be indented. Here, select all parts below the def statement as function content.
At this time, first press and hold the "shift" key, and then press the "tab" key. Remember to press it only once and release it immediately. At this point, as shown in Figure 1 below, an indentation is completed. If you long press or press the key combination multiple times, it will be indented multiple times, as shown in Figure 2 below, which is a multiple indentation effect. In this way, for versions 3.0 and above, the software comes with a program editor. How to achieve multi-line indentation is completed.
The above is the detailed content of How to quickly indent multiple lines of code in python program. For more information, please follow other related articles on the PHP Chinese website!