如何在python中打印特殊字符

时间:2015-11-19 21:29:06

标签: python

对于我的python程序,我想在控制台中打印特殊字符ℝ。我正在寻找一种简单的方法。

我的代码是:

a = int(input("a? "))
while a == 0 :
    a = int(input("a? "))
b = int(input("b? "))
c = int(input("c? "))

D = pow(b,2) - 4*a*c
if D>0:
    x1 = -b - pow(D,0.5)
    x1 = x1 / 2*a
    x2 = -b + pow(D,0.5)
    x2 = x2 / 2*a
    print("x1 = " + str(x1))
    print("x2 = "+ str(x2))
elif D==0:
    x0 = -b / 2*a
    print("x0 = " + str(x0))
else:
    print("Cette équation n'a pas de racines dans R")
input()

2 个答案:

答案 0 :(得分:3)

您将要打印unicode代码。

print(u"\u211D")

答案 1 :(得分:2)

首先查找unicode字符http://www.fileformat.info/info/unicode/char/211d/index.htm 然后你可以将unicode字符本身直接放在源代码中:

Python2:

print(u"ℝ")

Python3:

print("ℝ")

或使用转义码:

print("\u211D")

或者您可以将其存储为字节并对其进行解码:

bytes("\xE2\x84\x9D").decode('utf-8')