Home > Backend Development > Python Tutorial > What is the use of indentation in python

What is the use of indentation in python

(*-*)浩
Release: 2019-06-25 11:24:04
Original
6561 people have browsed it

Python is a very "unique" language!

why would you say so!

Because general languages ​​use {} or end as a mark for code blocks, while Python identifies code blocks through indentation.

What is the use of indentation in python

Regarding Python’s “indentation” style, people who like it say it is a pleasure; people who don’t like it say it is It is a language that requires calipers, because it is necessary to use a "vernier caliper" to measure the indentation of each line of code. (Recommended learning: Python video tutorial)

No matter what, the developers of Python intentionally prevent programs that violate the indentation rules from being compiled, so that Programmers develop good programming habits. And the Python language uses indentation to indicate the beginning and exit of statement blocks instead of using {} or other characters.

Today I will briefly introduce to you the method of indentation in Python!

Python’s indentation method

·Use the tab key

·Indent a few spaces (usually 4)

For example, the following example:

>>> if True:
…… print("this is true") //
…… print("this is true") //
…… else:
…… print("this is false")//
…… print("this is false")//
输出结果:
this is true
this is true
Copy after login

It should be noted that although Python syntax allows code blocks to be indented by any number of spaces, all statements located in the same code block must maintain the same indentation and cannot be indented at once. Indent by 3 spaces and 4 spaces at a time.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What is the use of indentation in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template