Python注释的作用
Comments can be used to explain Python code. (解释代码)
Comments can be used to make the code more readable. (提高代码的可读性)
Comments can be used to prevent execution when testing code. A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code.(在测试代码时,可以使用注释来阻止执行)
Python 注释的写法
1. 每行以#开头。(Comments starts with a #.)
#This is a comment
print("Hello, World!")
2. 以#开头,放在一行的末尾。(Comments can be placed at the end of a line, and Python will ignore the rest of the line.)
print("Hello, World!") #This is a comment
3. 多行注释,可以每行以#开头。(To add a multiline comment you could insert a # for each line.)
#This is a comment
#written in
#more than just one line
print("Hello, World!")
4. 多行注释,可以使用多行字符串(三引号)。(Use a multiline string. Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it. 由于 Python 将忽略未分配给变量的字符串文字,因此您可以在代码中添加多行字符串(三引号),并在其中添加注释)
"""
This is a comment
written in
more than just one line
"
""
print("Hello, World!")
注:英文和中文内容来自www.w3cschool.com
如果你有任何建议或想法,欢迎在下面留言告诉我哦!
也欢迎关注我的微信公众号:英语三年之约