看了看上一次学习居然是一个多月之前。。。鄙视自己一下,渐渐适应了工作,各种task也不断分派下来,但是这也不能成为我懒惰的借口。。。今天学习了一下第7个小节
Exercise7: More Printing 本节的内容从标题就能看出来,还是关于string的print,下面是例子,我会根据例子进行总结。
print "Mary had a little lamb." #print a string
print "Its fleece was white as %s." % 'snow' # format print
print "And everywhere that Mary went." #print a string
print "." * 10 #what'd that do? It print a '.
|
第一句和第三句根本没什么好说的,就是普通的print一个字符串,第二句在上一节其实也已经提过,无非是格式字符串的输出,类似printf,亮点在于最后一句,我一直在想,后面加上“* 10”,实际上是执行了10次
print "." * 10 呢,还是扩展成了
print ".........." 呢?亦或是
print "."+
"."+
"."+
"."+
"."+
"."+
"."+
"."+
"."+
"."呢?但是总之,打印出的效果是输出了10个"."
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后面的逗号,从最后的输出看,加上逗号表示前面输出的语句与后面输出的语句应该是衔接的关系,因为print输出会自动换行,但是加上逗号之后,两条print的语句输出在了一行上。
阅读(526) | 评论(0) | 转发(0) |