How to fill an entire string with * characters

I want to fill a whole line on the screen with * characters and stop in front of the interrupt line?

Something like that

 ********** MENU ********** 

thanks

+4
source share
2 answers
 >>> print(' MENU '.center(80, '*')) ************************************* MENU ************************************* 

Please note that 80 is not the actual width of the screen. This is just an arbitrary number that I choose, because this is the usual size of the console window on Windows. If you want to determine the actual width of the screen, you can try these examples for Linux and Windows .

+15
source

You can also do this using format strings.

 In [32]: '{0:*^80}'.format('MENU') Out[32]: '**************************************MENU**************************************' 

This expresses the use of the '*' character for padding 'MENU' up to 80 characters in the center. The symbol '^' indicates the center.

+4
source

Source: https://habr.com/ru/post/1497133/


All Articles