简体   繁体   中英

How to print math in python?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM