Python代码中添加注释

python中的注释

# prints 4

print(2 + 2)

print(2 + 3) # prints 5

"""

prints the sum of

two numbers which are 2 and 2

"""

print(2 + 2)


Python中的注释类型

Python支持编写简单的单行注释以及多行注释。

单行注释

# This is a simple comment

print(2 + 2)

print(2 + 3) # prints 5


多行注释

Python没有什么特别的东西可以写多行注释。要编写它，我们可以编写多个单行注释

# This statement

# prints the sum of

# two numbers which are 2 and 2

print(2 + 2)


Un-assigned string literal

"""

This statement

prints the sum of

two numbers which are 2 and 2

"""

print(2 + 2)