【问题标题】:How do I print something underlined in Python?如何在 Python 中打印带下划线的内容?
【发布时间】:2016-05-25 20:53:25
【问题描述】:
print("hello")

输出应该是单词“hello”,但带有下划线。

【问题讨论】:

标签: python printing console underline


【解决方案1】:

您可以使用转义字符来做到这一点。

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

【讨论】:

【解决方案2】:

你可以输入

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

【讨论】:

  • 这个解决方案给我以下输出:h_e_l_l_o
【解决方案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

【讨论】:

    【解决方案4】:

    确保你有 python3 解释器 然后运行

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

    【讨论】:

      【解决方案5】:

      这肯定会奏效:

      print("\u0332".join("hello "))
      

      【讨论】:

        【解决方案6】:

        确保您拥有 Python 3.6+ 使用 pip 安装 quo https://pypi.org/project/quo

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

        【讨论】:

          猜你喜欢
          • 2014-04-29
          • 1970-01-01
          • 2018-07-24
          • 2020-03-31
          • 1970-01-01
          • 2013-10-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多