《笨办法学Python》 第7课手记
本节课是为了巩固之前的内容,作者要求不能跳过所以就老老实实照做了。
代码如下:
print "Mary had a little lamb."
print "Its fleece was white as %s." %'snow'
print "And everywhere that Mary went."
print "." * 10 # what'd that do?
end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"
#watch that comma at the end. try removing it to see what happens
print end1 + end2 + end3 + end4 + end5 +end6,
print end7 + end8 + end9 + end10 + end11 + end12
结果如下:
注释里说的逗号问题,是指去掉倒数第二行代码的逗号,去掉逗号结果如下:
这里想说明的是输出字符串的格式问题,逗号表示该输出内容没有结束,即使回车到下一行,也会随着前一行输出;而去掉逗号,再回车到下一行则分行输出。
还有一点print “.” * 10 # what’d that do?
这里使用计算的方式给出了打印10个*号的方法,这个方法蛮不错的,记住它能简化代码。
剩下的常见问题解答已经说的很清楚了,这里不再赘述。