ex2.py
代码
# 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 5
# You can also use a comment to "disable" or comment out code
# print ("This won't run.")
print("This will run.")
'''-----------------------------------------------------------------------------'''
'''
1. 弄清楚 # 符号的作用,而且记住它的名字。(中文为井号,英文为 octothorpe 或者 pound character)。
加单行注释
2. 打开你的 ex2.py 文件,从后往前逐行检查每个单词,与要求输入的内容进行对比。
3. 有没有发现什么错误?有的话就改正过来.
4. 读你写的习题,把每个字符都读出来。有没有发现更多错误?有的话改正过来
'''
运行结果
问题
为什么在 print(“Hi # there.”) 里 # 就没有被忽略?
因为 # 在一个字符串里,计算机会打印引号之间字符串的所有内容, # 在字符串里被认为是一个字符,而不是注释符号。
我如何把很多行变成注释?
在每一行前面加一个 # 。
为什么我要倒着检查代码?
这是一个让你的大脑不专注于每行代码意思的小技巧,这样做能够让你更准确地检查出错误,可以说是一个很好用的纠错技巧了