Printing subscript in python

后端 未结 5 571
逝去的感伤
逝去的感伤 2020-12-03 01:53

In Python 3.3, is there any way to make a part of text in a string subscript when printed?

e.g. H₂ (H and then a subscript 2)

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 02:33

    Using code like this works too:

    print('\N{GREEK SMALL LETTER PI}r\N{SUPERSCRIPT TWO}')
    print('\N{GREEK CAPITAL LETTER THETA}r\N{SUBSCRIPT TWO}')
    

    The output being:

    πr²
    Θ₂
    

    Note that this works on Python versions 3.3 and higher only. Unicode formatting.

提交回复
热议问题