how to write subscript and superscript in python

Solutions on MaxInterview for how to write subscript and superscript in python by the best coders in the world

showing results for - "how to write subscript and superscript in python"
Ryder
25 Sep 2016
1# function to convert to subscript
2def get_sub(x):
3    normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-=()"
4    sub_s = "ₐ₈CDₑբGₕᵢⱼₖₗₘₙₒₚQᵣₛₜᵤᵥwₓᵧZₐ♭꜀ᑯₑբ₉ₕᵢⱼₖₗₘₙₒₚ૧ᵣₛₜᵤᵥwₓᵧ₂₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎"
5    res = x.maketrans(''.join(normal), ''.join(sub_s))
6    return x.translate(res)
7  
8# display subscript
9print('H{}SO{}'.format(get_sub('2'),get_sub('4'))) #H₂SO₄
10