Python 中的多行打印
我们经常在 Python 中看到 print 命令打印一行输出。但是,如果我们有多行要打印,那么,在这种方法中,需要编写多条 print 命令。通过使用下文中展示的三引号,可以避免这种情况。
示例
print(''' Motivational Quote :\n Sometimes later becomes never, Do it now. Great things never come from comfort zones. The harder you work for something, the greater you'll feel when you achieve it. ''')
运行以上代码会给我们以下结果
Motivational Quote : Sometimes later becomes never, Do it now. Great things never come from comfort zones. The harder you work for something, the greater you'll feel when you achieve it.
我们可以使用多行打印来制作无格式文本,如下所示。
示例
print(''' =========================================== || || || WORK || || HARD || || || || || || || =========================================== ''')
运行以上代码会给我们以下结果
============================= || || || WORK || || HARD || || || || || || || =============================
广告