笨办法学 Python--跟书练习二

简介: 笨办法学 Python--跟书练习二

习题 2: 注释和井号


程序里的注释是很重要的。它们可以用自然语言告诉你某段代码的功能是什么。在你想要临时移除一段代码时,你还可以用注解的方式将这段代码临时禁用。接下来的练习将让你学会注释:python2:


# A comment, this is so you can read your program later. # Anything after the # is ignored by python.
print "I could have code like this." 
# and the comment after is ignored
# You can also use a comment to "disable" or comment out a piece of code:
# print "This won't run."
print "This will run."


你应该看到的结果

640.png


【Python3的代码应该为:

# A comment,this is so you can read your program later.
# Anything after the # is ignored by python.
print ("I could have code like this.") # and the comment after is ignored
# You can also use a comment to "disable" or comment out a piece of code:
# print "This won't run."
print ("This will run.")

显示结果为:

640.png

640.png

加分习题:


1. 弄清楚”#”符号的作用。而且记住它的名字。(中文为井号,英文为 octothorpe 或者 pound character)。

2. 打开你的 ex2.py 文件,从后往前逐行检查。从最后一行开始,倒着逐个单词单词检查回去。

3. 有没有发现什么错误呢?有的话就改正过来.

4. 朗读你写的习题,把每个字符都读出来。有没有发现更多的错误呢?有的话也一样改正过来

相关文章
Python 练习实例26
Python 练习实例26
Python 练习实例25
Python 练习实例25
Python 练习实例35
Python 练习实例35
Python 练习实例34
Python 练习实例34
Python 练习实例21
Python 练习实例21
Python 练习实例20
Python 练习实例20
Python 练习实例33
Python 练习实例33
Python 练习实例24
Python 练习实例24
Python 练习实例36
Python 练习实例36

推荐镜像

更多