What symbol does a python comment start with?

(*-*)浩
Release: 2019-07-03 15:11:26
Original
13949 people have browsed it

There are many kinds of comments in python, including single-line comments, multi-line comments, batch comments, and Chinese comments are also commonly used. Python annotations also have their own specifications, which will be introduced in the article. Comments can serve as notes. When working in a team, code written by individuals is often called by multiple people. In order to make it easier for others to understand the flow of the code, using comments is very effective.

What symbol does a python comment start with?

1. python single-line comment symbol (#) (recommended learning: Python video tutorial)

The pound sign (#) is often used as a single-line comment symbol. When # is used in code, any data to the right of it will be ignored and treated as a comment. The content to the right of

print 1 #输出1
Copy after login

# will not be output during execution.

2. Batch and multi-line comment symbols

In python, there will also be comments with many lines. In this case, batch multi-line comment symbols are needed. . Multi-line comments are enclosed in triple quotes ''' ''', for example:

What symbol does a python comment start with?

Some people may say that this is not confused with multi-line strings. But I see many programmers using it this way, so just pay attention to the distinction when using it.

3. python Chinese comment method

When writing code in python, it is inevitable that Chinese will appear or be used. At this time, you need to add at the beginning of the file Chinese annotation. For example, create a python list and comment its purpose on the code. If you do not declare the format for saving the encoding at the beginning, then it will use ASKII code to save the file by default. At this time, if there is Chinese in your code, an error will occur. Even if your Chinese is included in the comments. So it is important to add Chinese comments.

#coding=utf-8
Copy after login

Or:

#coding=gbk
Copy after login

Tip: Both of the above can represent Chinese comments. I have seen more people using urf-8.

A good programmer must comment on the code. But make sure that the comments are all important. You can tell what it does at a glance. Useless code does not need to be commented.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What symbol does a python comment start with?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template