首先,我正在努力实现如下所示的期望输出:
*********************************************************************
hello
*********************************************************************
为了实现这一点,我已经将所需输出指定为一个具有多行字符串的变量,并使用format打印出相同结果。$ cat varibale.py
decorator = """ **********************************************************************
{}
********************************************************************** """
print(decorator.format("hello"))
输出:
**********************************************************************
hello
**********************************************************************
以上方法存在的问题是输出的第三行有额外空格,看起来很奇怪。
我能够通过以下方式实现:
Translated text:The issue with above approach is the extra spaces in the third line of output which is looking odd.
I am able to achieve this in the following way:
$ cat varibale.py
decorator = """ **********************************************************************
{}
*********************************************************************
"""
print(decorator.format("hello"))
输出:
**********************************************************************
hello
*********************************************************************
但是这样我的代码看起来不太好,因为它没有遵循缩进。
请建议实现所需输出的正确方法。