Python comment method

Comments in computer languages ​​basically have the same function. One is that I may use this code later, but it is useless now. I first comment here that it will not participate in the operation, but I think it will run normally after opening the comment directly.

Also use comments to explain what your code does

The method is that the single-line comment starts with a warning sign and the content on the right is the comment

print(666)
print(130.33)
#print("你好python")

insert image description here
Obviously, the last piece of code is grayed out, which means that it is a comment and will not affect the running of the code.

I also tried it here for everyone. Notes and content can be pasted together, but according to a specification of python, the distance between the alarm signal and the content should be kept one space away.

The specification is a kind of suggestion. If it is not followed, it will not affect the running of the program, but the code is beautiful and the running performance is often improved because of the code specification.

The method of python multi-line comment is a code fragment starting with three quotation marks and ending with three quotation marks

The reference code is as follows

"""
    print(666)
    print(130.33)
"""
# print("你好python")

insert image description here
In this way, the two lines of code above are also commented.

Then we look at the following code

# 利用print方法输出了一个值为 666 的整数字面量
print(666)
# 利用print方法输出了一个值为 130.33 的浮点数字面量
print(130.33)
# 利用print方法输出了一个值为 你好python 的字符串字面量
print("你好python")

Because the comment will not affect the running of the code, we can use it to help others understand our code.

But to be honest, it is more useful to annotate the code that may be used in the future but is not used now, so there is no need to delete it

After all, everyone does not write comments at work.
The two things that programmers hate the most are
1. Hate writing comments
2. Hate others not writing comments

おすすめ

転載: blog.csdn.net/weixin_45966674/article/details/130164142