Python center string using format specifier

前端 未结 2 935
迷失自我
迷失自我 2020-12-14 16:41

I have a string called message.

message = \"Hello, welcome!\\nThis is some text that should be centered!\"

And I\'m trying to

2条回答
  •  -上瘾入骨i
    2020-12-14 17:18

    You need to centre each line separately:

    '\n'.join('{:^80}'.format(s) for s in message.split('\n'))
    

提交回复
热议问题