How do I print something underlined in Python?

不羁的心 提交于 2019-12-13 11:52:11

问题


print("hello")

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


回答1:


You can do it by using escape characters.

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




回答2:


You may type

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




回答3:


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



来源:https://stackoverflow.com/questions/35401019/how-do-i-print-something-underlined-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!