10
print("hello")

The output should be the word "hello", but underlined.

Ricky Su
  • 285
  • 1
  • 6
  • 10
  • 1
    Possible duplicate of [How do I print bold text in Python?](http://stackoverflow.com/questions/8924173/how-do-i-print-bold-text-in-python) – Timothée Poisot Feb 15 '16 at 03:27

6 Answers6

27

You can do it by using escape characters.

print("\033[4mhello\033[0m")
dspencer
  • 3,898
  • 4
  • 19
  • 41
Akira Okumura
  • 1,706
  • 1
  • 19
  • 39
  • 2
    It's not working for me, it just print - [4mhello[0m – AlokThakur Feb 15 '16 at 07:27
  • @AlokThakur according to [this comment from a similar question](https://stackoverflow.com/questions/55065640/python-string-formatter-to-get-underlined-headline#comment96879594_55065815), it may not work on terminals that don't understand ANSI escape sequences. – syockit Jun 05 '20 at 00:37
  • See this answer to make it work in windows: https://stackoverflow.com/questions/12492810/python-how-can-i-make-the-ansi-escape-codes-to-work-also-in-windows/64222858#64222858 – Gary Vernon Grubb Oct 27 '20 at 08:18
1

You may type

print("\u0332".join("hello ")) enter image description here

WenHao1223
  • 19
  • 3
1

This will definitely work:

print("\u0332".join("hello "))
Costa
  • 1,171
  • 1
  • 9
  • 19
0
string = 'Hello world'
emptystring = ''

for i in range(0, len(string)):

    if string[i] == ' ':
        emptystring = emptystring + string[i]
    else:
        emptystring= emptystring+string[i]+str('\u0332')

print(emptystring)

Here is the output

Uday
  • 1
  • 1
0

make sure you have python3 interpreter then run

x="the solution"
print("\033[4m" + x + "\033[0m")
0

Make sure you have Python 3.6+ Install quo using pip https://pypi.org/project/quo

from quo import echo
echo(f"Hello World!!!", underline=True)