python中运算时用的乘法和除非符号是 * 和 % / 之类的,最近需要用到 ✖ 和 ➗ 两个字符串显示数据,找到了可实现的资料,分享给大家。
安装:pip install pylatexenc
代码实现:
In [11]: from pylatexenc.latex2text import LatexNodes2Text
In [12]: mul_symbol = r""" imes"""
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'