Tips for using the python language, and tips for using python

Source: Internet
Author: User

Tips for using the python language, and tips for using python

I

Before writing, you 'd better specify the python path:

#! /Usr/bin/python

Python needs to add encoding methods in linux: To avoid Chinese garbled characters

#-*-Coding: UTF-8 -*-

2. in various languages, Python should be the language that most uses indentation recognition. Even if there are multiple lines of its for statement, you do not need to think about java, C ++, c using the same {}, A line break can represent a sentence like JavaScript or swift, rather than a line break. If you have learned the language background, note the following:

In python's view:

 

 

If you change the indent method, for example, indent the second for, it will cause an error:

The following error occurs:

So the question is: what is the impact of line feed and indentation on python ???

 

The running results show that:

1. line feed can be considered as the; sign in java and c ++ without affecting the statement structure.

2 indentation with the same distance can be considered as a pair of {}, regardless of the language {} should appear in pairs.

The python statement that appears in demo1

It is equivalent:

It is because {} does not match. Therefore, the following error occurs:

IndentationError: unexpected indent

Or you can understand it as follows: statements with the same indentation can be viewed as code blocks {}

The above python usage tips are all the content shared by Alibaba Cloud. I hope you can give me a reference and support the help house.

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.