Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用*字符填充屏幕中的一整行并在换行之前停止?
*
像这样的东西
********** MENU **********
谢谢
>>> print(' MENU '.center(80, '*')) ************************************* MENU *************************************
请注意,80 并不是屏幕的实际宽度。这只是我选择的任意数字,因为它是 Windows 上控制台窗口的通常大小。如果您想确定实际的屏幕宽度,您可以尝试这些适用于Linux和Windows的示例。
您也可以使用格式字符串执行此操作
In [32]: '{0:*^80}'.format('MENU') Out[32]: '**************************************MENU**************************************'
这表示使用字符在中心'*'填充'MENU'到 80 个字符。'^'字符表示中心。
'*'
'MENU'
'^'