练习789:打印,打印,打印

Posted 测试情报局

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了练习789:打印,打印,打印相关的知识,希望对你有一定的参考价值。

打印函数:print

Python3中,print后要加括号:print()

 

print("练习7:更多打印")

#打印句子
print("solo had a little lamb.")
print("Its fleece was white as %s." %\'snow\')
print("And everywhere that Mary went.")
print("." * 10) #打印出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"
#打印
print(end1 + end2 + end3 + end4 + end5 + end6 ,end = " ")  # end = "" 表示下一行打印时不换hang;引号中间可加入空格、字符等
print(end7 + end8 + end9 + end10 + end11 + end12)
print("." * 10)

结果:

习题8:

print("习题8:打印,打印")

#变量指向格式化的字符串
formatter = "%r %r %r %r"

print (formatter %(1,2,3,4))#格式化的字符串被分别赋值1234
print(formatter %("one","two","three","four"))
print(formatter %(True,False,False,True))
print(formatter %(formatter,formatter,formatter,formatter))
print(formatter %(
    "I had this ting.",
    "That you could type up right.",
    "But it did\'t sing.",
    "so I said goodnight."
))

结果:

 

习题9:

print("习题9:打印,打印,打印")

days = "Mon Tue Wed Thu Fri Sat Sun"
#\\n 表示换行
months = "\\nJan\\nFeb\\nMar\\nApr\\nMay\\nJun\\nJul\\nAug"  

#打印出句子
print("Here are the days:",days)
print("Here are the months:",months)

#三引号适用于多行句子打印
print(
"""
there\'s somthing going on here.
with the three double-quotes.
we\'ll be able to type as much as we like.
Even 4 lines if we went,or 5,or 6.
"""
)

结果:

 

以上是关于练习789:打印,打印,打印的主要内容,如果未能解决你的问题,请参考以下文章

我的Android进阶之旅NDK开发之在C++代码中使用Android Log打印日志,打印出C++的函数耗时以及代码片段耗时详情

argparse 代码片段只打印部分日志

练习7--打印打印

PHP练习--用for循环打印空心菱形

Go练习题—动态打印歌词

Python实战练习——打印日历教程