![]() |
VOOZH | about |
Whenever we work with formulas, there may be a need to present them in a specific format, which may require subscripts or superscripts. In this article, we will explore how to print superscripts and subscripts in Python.
Unicode characters allow us to easily display superscript and subscript numbers in Python. By using specific Unicode symbols, we can directly include these characters in our strings without needing additional libraries.
a² H₂CO₃
Explanation:
This following table gives the subscripts and superscripts of the Unicode characters:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| U+207x | ⁰ | ⁱ | ⁴ | ⁵ | ⁶ | ⁷ | ⁸ | ⁹ | ⁺ | ⁻ | ⁼ | ⁽ | ⁾ | ⁿ | ||
| U+208x | ₀ | ₁ | ₂ | ₃ | ₄ | ₅ | ₆ | ₇ | ₈ | ₉ | ₊ | ₋ | ₌ | ₍ | ₎ | |
| U+209x | ₐ | ₑ | ₒ | ₓ | ₔ | ₕ | ₖ | ₗ | ₘ | ₙ | ₚ | ₛ | ₜ |
str.format() allows us to dynamically insert superscript and subscript characters into strings. By using Unicode, we can easily format expressions like formulas with special characters such as superscripts and subscripts.
x² H₂
Explanation:
F-strings make it easy to insert superscripts and subscripts into strings. They provide a clear and efficient way to combine text and special characters.
x² H₂
Explanation:
Related Articles: