Bonsoir,
à ma connaissance il n'existe pas de méthode sur les objets str permettant de basculer en exposant comme le permet par exemple de basculer du texte en capital avec "test".upper()
Le seul moyen est donc d'utiliser les caractères unicodes existants: https://en.wikipedia.org/wiki/Unicod...d_superscripts

Envoyé par
Wikipedia: Superscripts and subscripts block
The most common superscript digits (1, 2, and 3) were in ISO-8859-1 and were therefore carried over into those positions in the Latin-1 range of Unicode. The rest were placed in a dedicated section of Unicode at U+2070 to U+209F.
Python 2 :
print(", ".join(["x" + unichr(u) for u in (0x2070, 0x00B9, 0x00B2, 0x00B3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079)]))
Python 3 :
print(", ".join(["x" + chr(u) for u in (0x2070, 0x00B9, 0x00B2, 0x00B3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079)]))
Qui donne ceci si la police de caractère le supporte :
x⁰, x¹, x², x³, x⁴, x⁵, x⁶, x⁷, x⁸, x⁹
Partager