How can i put formated text in python? (bold, italic, etc.) | SoloLearn: Learn to code for FREE!

+6

How can i put formated text in python? (bold, italic, etc.)

formated text in python? (bold, italic, etc.)

6/25/2020 8:00:50 AM

Ayush Dwivedi 🇮🇳

7 Answers

New Answer

+2

Tricker red = '\033[91m' green = '\033[92m' blue = '\033[94m' bold = '\033[1m' italics = '\033[3m' underline = '\033[4m' end = '\033[0m' print (red + underline + 'Test!... Test!' + end) something like this?

+3

A little more pythonic Module: https://gist.github.com/dnmellen/5584007 import colors with colors.pretty_output(colors.BOLD, colors.FG_GREEN) as out: out.write("This is a bold green text") with colors.pretty_output(colors.BG_BLUE) as out: out.write("This output have a blue background but you " + colors.BOLD + colors.FG_RED + "can" + colors.END + " mix styles")

+2

Thanks for the help Ruben Gasparyan

+1

You are welcome!

0

Hi, for example from terminal import render print render('%(BG_YELLOW)s%(RED)s%(BOLD)sHey this is a test%(NORMAL)s') print render('%(BG_GREEN)s%(RED)s%(UNDERLINE)sAnother test%(NORMAL)s') you can change background color, color and formated text

0

You can also do it by using custom gui shell or ANSI escape characters. For Bold it's , "\033[3m" E.g. print('\003[3m' + 'Your text here' + '\033[0m') Always end your string with '\033[0m' There are many more formats available, use wiki for that. However, Sololearn shell doesn't support ANSI chars, therefore it is not possible here.

0

Ayush Dwivedi 🇮🇳 yes. You can also use semi colon for multi formatting.