Underline String in Python

  • Post category:String

In this article, you will see how to underline string in Python. To underline a string in Python, you can use the string format() method. The below code 4m{} is used to underline a string.

Step 1: Create a string

str = "CodeAllow"
print("str = ", str)
print("str type = ", type(str))

Step 2: Underline string

print("str = ", "\033[4m{}\033[0m".format(str))

Output:

str =  CodeAllow
str type =  <class 'str'>
str =  CodeAllow

Free resources to learn advanced skills: AiHints and CodeAllow