How to print math symbols in python?

Viewed 4784

I would like to print math in python with print(), as it is possible to do in plot's label with matplotlib (see this link for all the math you can write with matplotlib https://matplotlib.org/tutorials/text/mathtext.html ) Is that even possible ? I tried the following (as in matplotlib):

print(r'$\Delta v$:', delta)

to print a greek delta for example, but it doesn't work (as it's not a matplotlib function), it shows : $\Delta v$: delta

2 Answers

You can actually print the characters with no issue in Python. Just find the associated unicode characters with a Google search and copy/paste them into your print statement.

print('Δ')
print('α')

No, it is generally not possible to do this using the print function - it just outputs plain text to standard output. matplotlib can render math text as, for instance, a plot title, because its target is the generated image.

Like Kurt Kline said, you can display simple characters, but not complex expressions like a sum symbol or superscripts.

Related