您的位置:首页 > 编程语言 > Python开发

python学习笔记2:print的使用中的一些问题

2017-10-11 22:54 676 查看
本篇博文,总结一些在程序设计过程中使用print遇到的一些问题

1、使用print输出多个重复字符,我们可以使用如下程序

print "." * 10


结果:..........

2、在print的结尾加入“,”可以续行,并产生空格

end1 = "C"

end1 = "C"

end2 = "h"

end3 = "e"

end4 = "e"

end5 = "s"

end6 = "e"

end7 = "B"

end8 = "u"

end9 = "r"

end10 = "g"

end11 = "e"

end12 = "r"

print end1 + end2 + end3 + end4 + end5 + end6,

print end7 + end8 + end9 + end10 + end11 + end12

结果:Cheese Burger

3、先看程序

print “%r %r %r %r” % (

    "I had this thing.",

    "That you could type up right.",

    "But it didn't sing.",

    "So I said good night."

)

结果:'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said good night.'

解释:使用“%r”,系统会根据需要输出双引号或者单引号,不要太在意

4、先看程序

print """

There's something going on here.

With the three double-quotes.

We'll be able to type as much as we like.

Even 4 lines if we want, or 5, or 6.

"""

结果:

There's something going on here.

With the three double-quotes.

We'll be able to type as much as we like.

Even 4 lines if we want, or 5, or 6.

解释:3引号中的内容会原样输出

原创性文章,转载请注明出处      

CSDN:http://blog.csdn.net/qingwufeiyang12346。 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python print