Reputation: 9
I've been trying to append a unit into a calculated value using the print statement in python 3, but I can't seem to find a way to get the unit to print as a superscript.
print ("I max = ", np.amax(intensity363), "J m$^-2$")
I've currently got tex, but I've tried html style with as I do it on a graph axes, and various other options listed in this post
How do you print superscript in Python?
but none work, given the age of this post I'm wondering if its a python 2/3 thing.
Thanks for the help
Upvotes: 0
Views: 6281
Reputation: 21663
As I see that you're working with Jupyter you might be interested in this approach, if indeed you're not already using it.
This is done in Py2 only because I haven't installed Py3 in Jupyter. I expect it works in essentially the same way.
Upvotes: 0
Reputation: 7562
There's no such a built-in feature. You can use Unicode if you need some fancy symbols, e.g.
>>> print("%d⁻²" % 42)
42⁻²
You need to look up the different codes if you need something more dynamic than just the "-2".
Upvotes: 3