How to print a message box in python?
python string
I'm trying to print out a message within a created box in python, but instead of it printing straight down, it prints horizontally.
When you use list comprehension you get the output as list , as seen by your output, to see the new line character you need to print the result
And also you are using columns to multiply - which is only one for all strings. Change it to `row'
def border_msg(msg): row = len(msg) h = ''.join(['+'] + ['-' *row] + ['+']) result= h + '\n'"|"+msg+"|"'\n' + h print(result)
The above answers are good if you only want to print one line, however, they break down for multiple lines. If you want to print multiple lines you can use the following:
This will print a box around a multi-line string that is left-aligned with the specified padding values determining the positioning of the text in the box. Adjust accordingly.
If you would like to center the text, just use one padding value and interleave half of the spaces value from the spaces = h_len - len(m) line between the pipes.
Here's a mildly elaborated function for printing a message-box with optional title and indent which centers around the longest line:
"
#programmingknowledge #codewithharry #coder #pandas #trending #flask #Django #mail #bottel #begginers #jinja #dynamicprograming #specialcode
На этой странице сайта вы можете посмотреть видео онлайн Box input text in Python || Python for begginers || basic code in python длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Sachin Meena 31 Январь 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 102 раз и оно понравилось 5 зрителям. Приятного просмотра!