Error IndentationError: unexpected indent prompted during python3.4 Compilation

Source: Internet
Author: User

Problem description:

Compile (well, it should be called "explanation") a python program prompts a special error:

IndentationError: unexpected indent



Problem Analysis: according to the following error message after compilation (after explanation), the "p" of print is an IndentationError: unexpected indent. What does it mean?

Indentation refers to indentation and contraction. Unexpected indent means "p" is an "unexpected" indent. That is to say, the problem here is that "p" is an unexpected indent. By checking the source code, we can see a total of two sentences of code. The first sentence is indeed Indented by a character bit. Based on this, we can infer that we have removed the indentation of this sentence, that is, the top level (the top level of the word suddenly reminds me of the elementary language class). What will happen after I explain it?

Experiment:


Now, the two statements of code are written in the "top level" format. After the explanation, there is no problem.

In order to further prove that "every sentence must be written at the top level", we keep the first code at the top level and indent the second sentence to a single character. . <Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140515/20140515090701152.jpg" alt = "">

The result shows that the second line is IndentationError and the indentation is incorrect.

So far, we come to the conclusion:

In python, every sentence of code should be written in the top level.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.