python 显示乘法符号和除法符号(python print multiplication symbol and division symbol)

 

python中运算时用的乘法和除非符号是 * 和 % / 之类的,最近需要用到 ✖ 和 ➗ 两个字符串显示数据,找到了可实现的资料,分享给大家。

参考资料:https://stackoverflow.com/questions/65607397/how-do-i-display-the-multiplication-and-division-symbol-using-pytexit

安装:pip install pylatexenc

代码实现:

In [11]: from pylatexenc.latex2text import LatexNodes2Text

In [12]: mul_symbol = r"""\times"""

In [13]: div_symbol = r"""\div"""

In [14]: mul_symbol
Out[14]: '\\times'

In [15]: div_symbol
Out[15]: '\\div'

In [16]: mul_symbol_text = LatexNodes2Text().latex_to_text(mul_symbol)

In [17]: div_symbol_text = LatexNodes2Text().latex_to_text(div_symbol)

In [18]: mul_symbol_text
Out[18]: '×'

In [19]: div_symbol_text
Out[19]: '÷'

In [20]: "6" + div_symbol_text + "3 = 2"
Out[20]: '6÷3 = 2'

 

posted @ 2021-04-22 11:05  ttweixiao9999  阅读(1769)  评论(0编辑  收藏  举报