我想要这个:
============================= thread: 1 starting ==============================使用我发现的.format方法实现这一目标的唯一方法是:
print("{:=^79}".format(' Thread: ' + self.thread_id + ' starting '))有更好的方法吗?因为这有点难读,而且有点违背了整个.format的原则,即左边有字符串,右边有值。
发布于 2014-06-27 08:22:56
正如@Felix所指出的,您可以使用center
>>> ' Thread: {} starting '.format(42).center(79, '=')
'============================= Thread: 42 starting ============================='或者你可以筑巢format。
>>> '{:=^79}'.format(' Thread: {} starting '.format(42))
'============================= Thread: 42 starting ============================='https://stackoverflow.com/questions/24446943
复制相似问题