Python多行打印
我们通常在python中看到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 || || || || || || || =============================