Superscript & Subscript
Convert text to Unicode superscript or subscript characters. Supports digits, letters, and common symbols.
Supported characters:
Digits 0-9: ⁰¹²³⁴⁵⁶⁷⁸⁹
Pertanyaan yang Sering Diajukan
Implementasi Kode
SUPERSCRIPT = str.maketrans(
"0123456789abcdefghijklmnoprstuvwxyzABDEGHIJKLMNOPRTUVW+-=()",
"⁰¹²³⁴⁵⁶⁷⁸⁹ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖʳˢᵗᵘᵛʷˣʸᶻᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴿᵀᵁⱽᵂ⁺⁻⁼⁽⁾"
)
SUBSCRIPT = str.maketrans(
"0123456789aehijklmnoprstx+-=()",
"₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜₓ₊₋₌₍₎"
)
def to_superscript(text: str) -> str:
return text.translate(SUPERSCRIPT)
def to_subscript(text: str) -> str:
return text.translate(SUBSCRIPT)
print(to_superscript("x2 + y2 = r2")) # x² + y² = r²
print(to_subscript("H2O")) # H₂OComments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.