Answers for "how to write subscript and superscript in python"

0

how to write subscript and superscript in python

# function to convert to subscript
def get_sub(x):
    normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-=()"
    sub_s = "ₐ₈CDₑբGₕᵢⱼₖₗₘₙₒₚQᵣₛₜᵤᵥwₓᵧZₐ♭꜀ᑯₑբ₉ₕᵢⱼₖₗₘₙₒₚ૧ᵣₛₜᵤᵥwₓᵧ₂₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎"
    res = x.maketrans(''.join(normal), ''.join(sub_s))
    return x.translate(res)
  
# display subscript
print('H{}SO{}'.format(get_sub('2'),get_sub('4'))) #H₂SO₄
Posted by: Guest on June-16-2021

Code answers related to "how to write subscript and superscript in python"

Python Answers by Framework

Browse Popular Code Answers by Language