The usage and specification of single and multiline annotations in Pyhton _python

Source: Internet
Author: User
Tags in python

Objective

Annotations can play a role in a note, when the team work, the individual code is often called by many people, in order to make it easier for others to understand the thoroughfare of the Code, the use of annotations is very effective.

Python annotation Character

One, Python single-line annotation symbol (#)

The pound sign (#) is often used as a single-line annotation symbol, and any data on the right side of it is ignored as a comment when using # in code.

Print 1 #输出1

#号右边的内容在执行的时候是不会被输出的.

Second, batch, multiline annotation symbol

There are also many lines of annotations in Python, in which case a lot of multiline annotation characters are required. Multiline annotations are contained in triple quotes ' ', such as:


Some people may say that this is not confused with a multi-line string, but many of the programmers I see are doing the same, and it's good to be careful when using them.

Three, Python Chinese annotation method

When you write code in Python, you don't have to be able to see or use Chinese, you need to add a Chinese comment at the beginning of the file. If the beginning does not declare what the format of the saved encoding is, then it defaults to saving the file with the Askii code, so if you have Chinese in your code, it will go wrong, even if your Chinese is included in the annotation. So it's important to add a Chinese annotation.

#coding =utf-8
or:
#coding =GBK

Hint: Both of the above can represent the Chinese annotation, I have seen more people use urf-8 this kind of more.

Summarize

A good programmer, it is necessary to annotate code. But make sure that annotations are important things, like a glimpse of what you're doing, and that useless code doesn't need to be commented on. The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help.

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.