10

I want to fill an entire line in the screen with * characters and stop just before break line?

Something like this

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

Thanks

Viktor Kerkez
  • 45,070
  • 12
  • 104
  • 85
Marco Herrarte
  • 1,540
  • 5
  • 21
  • 42
  • 4
    IMO, the question is quite clear, and the accepted answer is excellent. The answer also clarifies what the asker wanted, and at least Viktor Kerkez was able to understand what he wanted. Bear in mind that the asker's English may not be perfect. Anyway, the asked problem is common for beginners who write the tutorial code with simple, text-line-oriented output. If I could, I would vote for protecting the question. Possibly, one of the complainers could edit the question for Kuait so that it would be acceptable ;) – pepr Aug 16 '13 at 08:33

2 Answers2

21
>>> print(' MENU '.center(80, '*'))
************************************* MENU *************************************

Note that 80 is not the actual width of the screen. It's just an arbitrary number I choose because it's the usual size of the console window on Windows. If you want to determine the actual screen width you can try these examples for Linux and Windows.

Community
  • 1
  • 1
Viktor Kerkez
  • 45,070
  • 12
  • 104
  • 85
  • I like this much better than mine. Format strings make me a bit anxious because I can never remember the syntax for all the awesome things you can do with them. – Phillip Cloud Aug 19 '13 at 16:00
6

You can also do this with format strings

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

This says use the '*' character to pad 'MENU' to 80 characters in the center. The '^' character indicates center.

Phillip Cloud
  • 24,919
  • 11
  • 68
  • 88