多应用+插件架构,代码干净,支持一键云编译,码云点赞13K star,4.8-4.12 预售价格198元 广告
# 习题 2: 注释和井号 程序里的注释是很重要的。它们可以用自然语言告诉你某段代码的功能是什么。在你想要临时移除一段代码时,你还可以用注解的方式将这段代码临时禁用。接下来的练习将让你学会注释: <table class="highlighttable"><tbody><tr><td class="linenos"> <div class="linenodiv"> <pre>1&#13; 2&#13; 3&#13; 4&#13; 5&#13; 6&#13; 7&#13; 8&#13; 9</pre> </div> </td> <td class="code"> <div class="highlight"> <pre># A comment, this is so you can read your program later.&#13; # Anything after the # is ignored by python.&#13; &#13; print "I could have code like this." # and the comment after is ignored&#13; &#13; # You can also use a comment to "disable" or comment out a piece of code:&#13; # print "This won't run."&#13; &#13; print "This will run."&#13; </pre> </div> </td> </tr></tbody></table> 从现在开始,我将用这样的方式来写代码。我一直在强调“完全相同”,不过你也不必按照字面意思理解。你的程序在屏幕上的显示可能会有些不同,不过重要的是你在文本编辑器中输入的文本的正确性。事实上,我可以用任何编辑器写出这段程序,而且内容是完全一样的。 ### 你应该看到的结果 ~~~ $ python ex2.py I could have code like this. This will run. $ ~~~ 再次说明,我不会再贴各种屏幕截图了。你应该明白上面的内容是输出内容的字面翻译,而 $python... 和最后的 $ 之间才是你应该关心的内容。 ### 加分习题 1. 弄清楚”#”符号的作用。而且记住它的名字。(中文为井号,英文为 octothorpe 或者 pound character)。 1. 打开你的 ex2.py 文件,从后往前逐行检查。从最后一行开始,倒着逐个单词单词检查回去。 1. 有没有发现什么错误呢?有的话就改正过来. 1. 朗读你写的习题,把每个字符都读出来。有没有发现更多的错误呢?有的话也一样改正过来。