如何写大写希腊语"delta"作为 Python 2.7 中的字符串? [英] How do I write a capital Greek "delta" as a string in Python 2.7?
本文介绍了如何写大写希腊语"delta"作为 Python 2.7 中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找这个字符:Δ
,我需要它作为 matplotlib 中的图例项.Python 3.x具有包含Unicode字符的 str
类型,但是我找不到有关如何在Python 2.7中进行操作的任何有价值的信息.
x = 范围(10)y = [5] * 10z = [y[i] - x[i] for i in xrange(10)]plt.plot(x,z,label ='Δx,y')plt.legend()plt.show()
<块引用>
UnicodeDecodeError: 'ascii' 编解码器无法解码字节 0xce 的位置0:序数不在范围内(128)
解决方案
尽管@ berna1111的注释正确,但您无需使用LaTeX格式即可获取∆字符.在 python 2 中,您需要使用 u''
构造( 解决方案
Although @berna1111's comment is correct, you don't need to use LaTeX format to get a ∆ character.
In python 2, you need to specify that a string is unicode by using the u''
construct (see doc here). E.g.:
plt.plot(x,z,label=u'Δ x,y')
这篇关于如何写大写希腊语"delta"作为 Python 2.7 中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文