Box input text in Python || Python for begginers || basic code in python

Veröffentlicht am: 31 Januar 2020
auf dem Kanal: Sachin Meena
102
5

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


Auf dieser Seite können Sie das Online-Video Box input text in Python || Python for begginers || basic code in python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Sachin Meena 31 Januar 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 102 Mal angesehen und es wurde von 5 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!