How do I print something underlined in Python?

27,414

Solution 1

You can do it by using escape characters.

print("\033[4mhello\033[0m")

Solution 2

You may type

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

Share:
27,414
Admin
Author by

Admin

Updated on August 09, 2021

Comments

  • Admin
    Admin almost 3 years
    print("hello")
    

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

  • AlokThakur
    AlokThakur over 8 years
    It's not working for me, it just print - [4mhello[0m
  • syockit
    syockit about 4 years
    @AlokThakur according to this comment from a similar question, it may not work on terminals that don't understand ANSI escape sequences.
  • Gary Vernon Grubb
    Gary Vernon Grubb over 3 years
    See this answer to make it work in windows: stackoverflow.com/questions/12492810/…
  • Ahmed Akhtar
    Ahmed Akhtar almost 3 years
    This solution gives the following output to me: h_e_l_l_o