如何为总和的每一项写评论?
How to write a comment for every term of a sum?
我是 Python 新手。
我想让我的代码得到很好的评论。
例如,在 C 中,我可以自然地为表达式的每个术语编写单行注释:
int hello_world_length =
5 + // length of "Hello"
1 + // space between words
5; // length of "World"
如何在 Python 中编写相同的语句?
我试过的代码:
hello_world_length =
5 + # length of "Hello"
1 + # space between words
5 # length of "World"
hello_world_length =
5 + # length of "Hello"
1 + # space between words
5 # length of "World"
hello_world_length = \
5 + # length of "Hello" \
1 + # space between words \
5 # length of "World"
以上都不行。
我已阅读 Python 教程,但没有找到解决方案。
只需将 right-hand 边用括号括起来。 4-space 缩进很常见:
hello_world_length = (
5 + # length of "Hello"
1 + # space between words
5 # length of "World"
)
print(hello_world_length)
11
我是 Python 新手。
我想让我的代码得到很好的评论。
例如,在 C 中,我可以自然地为表达式的每个术语编写单行注释:
int hello_world_length =
5 + // length of "Hello"
1 + // space between words
5; // length of "World"
如何在 Python 中编写相同的语句?
我试过的代码:
hello_world_length =
5 + # length of "Hello"
1 + # space between words
5 # length of "World"
hello_world_length =
5 + # length of "Hello"
1 + # space between words
5 # length of "World"
hello_world_length = \
5 + # length of "Hello" \
1 + # space between words \
5 # length of "World"
以上都不行。
我已阅读 Python 教程,但没有找到解决方案。
只需将 right-hand 边用括号括起来。 4-space 缩进很常见:
hello_world_length = (
5 + # length of "Hello"
1 + # space between words
5 # length of "World"
)
print(hello_world_length)
11