注释 (Comments)

在写Python 程序时,我们可以用 # 来添加注释。注释 在代码中并不会对程序造成影响。 # 符号之后的任何内容都是注释的一部分,会在程序执行时被忽略。我们在代码中加注释来告诉读者这些代码在做什么。它们可以使维护代码变得更容易,还可以帮助查找代码中的错误。

在编写代码时,我们一直用 # 来添加注释来帮助理解。

# This is my first line of code
print("Hello, World!)

Screenshot showing the comment This is my first line of code.

小心,如果你删除了 # 符号, 代码就无法正常运行了!

Screen shot of the code showing removal of the # before the comment causing an error in the code execution

试着在你的第一行代码前添加注释然后点击运行。你会发现电脑会在程序运行时忽略你的注释。