首页 » Python » 《笨方法学python》第四天:print,print,全他妈的print。

《笨方法学python》第四天:print,print,全他妈的print。

 

习题8,自己看注释。还是这样爽
#8 print print
#coding:utf-8
formatter = '%r %r %r %r' #故弄玄虚
print formatter %(1,2,3,4)#还可以这样┭┮﹏┭┮,这句其实等于 print '%r %r %r %r' %(1,2,3,4)
print formatter %('one','two','three','four')
print formatter %(formatter,formatter,formatter,formatter)
print formatter %(
'i had this thing',
'that you could type up right.',
"but it didn't sing.",#因为里面出现了单引号,所以要用双引号来括
'so i said goodnight.'
)

习题9:同上
#coding:utf-8
days = 'mon tue wed thu fri sat sun'
months = 'jan\nfeb\nmar\napr\nmay\njun\njul\naug'

print 'here are the days:', days
print 'here are the months:', months
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.
"""
#python 三引号的形式用来输入多行文本,也就是说在三引号之间输入的内容将被原样保留,之中的单号和双引号不用转义,其中的不可见字符比如/n和/t都会被保留,这样的好处是你可以替换一些多行的文本。

原文链接:《笨方法学python》第四天:print,print,全他妈的print。,转载请注明来源!

0