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

Publié le: 31 janvier 2020
sur la chaîne: 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


Sur cette page du site, vous pouvez voir la vidéo en ligne Box input text in Python || Python for begginers || basic code in python durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Sachin Meena 31 janvier 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 102 fois et il a aimé 5 téléspectateurs. Bon visionnage!