Python language Tips

Source: Internet
Author: User

One

It is a good idea to specify the path to Python before writing:

#!/usr/bin/python

Python needs to be encoded in Linux: to avoid garbled Chinese

#-*-coding:utf-8–*-

Two in all kinds of languages, Python should be the most use of the language of indentation, his for statement even if there are many lines do not need to think java,c++, C like the use of {}, can be like JS, Swift with a newline character to represent a sentence, rather than use; Students who have studied the language background please note:

In Python's view:

If you change the way indentation is indented, such as indenting on the second for, it causes an error:

The following errors occur:

So here's the question: What's the effect of line break and indentation on Python???

The results of the operation are as follows:

1 line breaks can be thought of as Java, C + +, and no effect on the structure of the statement.

2 indents of the same distance can be treated as a pair of {}, regardless of whether the {} In any language should appear in pairs.

This Python statement that appears in the Demo1

It is equivalent to:

This is because {} does not match. That's why one of the following errors occurs

indentationerror:unexpected Indent

Or you can understand that a statement with the same indentation can be seen as a code block {}

Python language Tips

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.