I'm writing a Python program to display the binomial expansion of (x + y)^k. Superscript characters work for 0, 1, 2, 3, and 5 through 9, but the superscript 4 (⁴) appears blank. The same string seems to contain the character correctly, so I'm trying to understand why only this character fails and whether the issue is with Python, Unicode, the terminal, or the font being used.
3 Answers
The character itself is valid Unicode: ⁴ is U+2074 SUPERSCRIPT FOUR. Python can print it, but your terminal, browser, or selected font may not have a glyph for it. The characters ¹, ², and ³ are older Latin-1 characters, while ⁴ and most of the other superscripts come from a different Unicode block. Try running the program in another terminal or with a font that supports the Superscripts and Subscripts block.
It works correctly in several environments, including a local terminal, so this probably isn't a Python problem. A quick test is to save the output to a UTF-8 file and open it in an editor or browser. If ⁴ appears there, the output device is missing the necessary font glyph or is mishandling Unicode display.
You can build exponents by mapping each digit to its superscript character, for example: `superscripts = {'0':'⁰','1':'¹','2':'²','3':'³','4':'⁴','5':'⁵','6':'⁶','7':'⁷','8':'⁸','9':'⁹','-':'⁻'}` and then joining the mapped characters. Just remember that this only affects how the result is displayed; the terminal still needs Unicode and font support to render every glyph.

That makes sense. In the online editor it sometimes appears blank even though the character is being processed, and restarting the program occasionally makes it show up.