![“笨办法”学Python 3](https://wfqqreader-1252317822.image.myqcloud.com/cover/22/26473022/b_26473022.jpg)
上QQ阅读APP看书,第一时间看更新
习题2 注释和#号
![](https://epubservercos.yuewen.com/B8CEE1/14969664205993406/epubprivate/OEBPS/Images/Figure-0029-0015.jpg?sign=1739032303-cNhA3N0WFKeFPq6bJ0dd5l98RKOW3fZ7-0-2d35b95ea4b64e48cf487a7e0f7d8c94)
程序里的注释是很重要的。它们可以用自然语言告诉你某段代码的功能是什么。想要临时移除一段代码时,你还可以用注释的方式临时禁用这段代码。这个习题就是让你学会如何在Python中使用注释。
ex2.py
1 # A comment, this is so you can read your program later. 2 # Anything after the # is ignored by python. 3 4 print("I could have code like this.")# and the comment after is ignored 5 6 # You can also use a comment to "disable" or comment out code: 7 # print("This won′t run.") 8 9 print("This will run.")
从现在开始,我将用这样的方式来演示代码。我一直在强调“完全一样”,不过你也不必按照字面意思理解。你的程序在屏幕上的显示可能会有些不同,重要的是你在文本编辑器中录入的文本的正确性。事实上,我可以用任何编辑器写出这段程序,而且内容是完全一样的。