[英]How to print a special character in 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()
您將要打印unicode代碼。
print(u"\ℝ")
首先查找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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.