Home  >  Article  >  Backend Development  >  How to quickly indent multiple lines of code in python program

How to quickly indent multiple lines of code in python program

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-22 17:36:416299browse

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.

How to quickly indent multiple lines of code in python program

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.

How to quickly indent multiple lines of code in python program

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.

How to quickly indent multiple lines of code in python program

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.

How to quickly indent multiple lines of code in python program

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.

How to quickly indent multiple lines of code in python program

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.

How to quickly indent multiple lines of code in python program

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.

How to quickly indent multiple lines of code in python program

How to quickly indent multiple lines of code in python program

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn