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
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on August 09, 2021Comments
-
Admin almost 3 years
print("hello")
The output should be the word "hello", but underlined.
-
AlokThakur over 8 yearsIt's not working for me, it just print - [4mhello[0m
-
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 over 3 yearsSee this answer to make it work in windows: stackoverflow.com/questions/12492810/…
-
Ahmed Akhtar almost 3 yearsThis solution gives the following output to me: h_e_l_l_o