Python learning: indentationerror:expected an indented block error resolution

Source: Internet
Author: User

The Python language is a language that is very sensitive to indentation, confusing to many beginners, and even a very experienced Python programmer can be caught in a trap. The most common scenario is that the mix of tab and space results in an error, or indentation is incorrect, which is not possible with the naked eye.


This error will occur at compile time indentationerror:expected an indented block indicates that indentation is required here, as long as you press space or tab (but not mix) to indent the line in the wrong line.

Often some people will question: I do not indent how or wrong, the indentation of the place will be indented, non-indentation will be wrong, such as:


Mode one:

#coding: Utf-8



money=["Zhang Total", "Wang Total", "Li Total", "Liu Manager", "Cleaning Wu Aunt", "Programmer's Me"]


For Mans in Money:

Print Mans

Print Len (Money)


Operation Result:

D:\pf\python> Python test.py

File "test.py", line 7

Print Mans

^

Indentationerror:expected an indented block



Mode two:

#coding: Utf-8



money=["Zhang Total", "Wang Total", "Li Total", "Liu Manager", "Cleaning Wu Aunt", "Programmer's Me"]


For Mans in Money:

Print Mans

Print Len (Money)


Run results

D:\pf\python> Python test.py

Briefly

6

General Wang

6

Cfic

6

Manager Liu

6

Cleaning Wu Aunt

6

Programmer's Me

6


Mode three:

#coding: Utf-8



money=["Zhang Total", "Wang Total", "Li Total", "Liu Manager", "Cleaning Wu Aunt", "Programmer's Me"]


For Mans in Money:

Print Mans

Print Len (Money)


Operation Result:

D:\pf\python> Python test.py

Briefly

General Wang

Cfic

Manager Liu

Cleaning Wu Aunt

Programmer's Me

6


This article is from the "Clear" blog, please be sure to keep this source http://chebgming001.blog.51cto.com/7935897/1685275

Python learning: indentationerror:expected an indented block error resolution

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.