[問題] 關於print 上標 下標 字體

看板Python作者 (福斯梯Z)時間7年前 (2018/07/25 15:39), 7年前編輯推噓3(305)
留言8則, 4人參與, 7年前最新討論串1/1
各位版友好 最近剛看書, 學到def 就寫了一個輸入半徑 算出圓形面積 簡單程式如下 def area(radius): result = radius * radius * 3.14 return result i = int(input('Please enter the radius (in CM): ')) print ('The area is %5.2f CM2: ' % area(i)) 突然想到一個問題 我想要把print出的CM2 變成 CM2 (2上標) 搜尋了Google,好像沒有看到有用的資訊 ============================================ 如 http://wiki.python.org.tw/%E8%AA%AA%E6%98%8E/%E6%8E%92%E7%89%88 範例中的 上標字與下標字 You might recall ''a''^2^ + ''b''^2^ = ''c''^2^ from your math lessons, unless your head is filled with H,,2,,O. 結果: You might recall a2 + b2 = c2 from your math lessons, unless your head is filled with H2O. 我按照教學 x = ("You might recall ''a''^2^ + ''b''^2^ = ''c''^2^ from your math lessons, unless your head is filled with H,,2,,O.") print (x) 結果: You might recall ''a''^2^ + ''b''^2^ = ''c''^2^ from your math lessons, unless your head is filled with H,,2,,O. 沒變啊!!!! 請問在不用import的方式, 可以把CM2 的2上標嗎? 感謝 -- ※ 編輯: FoxTz (36.228.236.116), 07/25/2018 15:39:28

07/25 15:48, 7年前 , 1F
print(u'a\u00b2+b\u00b2=c\u00b2')
07/25 15:48, 1F

07/25 17:58, 7年前 , 2F
推樓上,第一次學到py也可以這麽打....
07/25 17:58, 2F

07/25 19:23, 7年前 , 3F
意義不大。早期數學式的表示要嘛透過 HTML 要嘛就是用 ^
07/25 19:23, 3F

07/25 19:24, 7年前 , 4F
代表次方項。在 console 介面作這種事情根本沒意義,關
07/25 19:24, 4F

07/25 19:24, 7年前 , 5F
於這部份去找一份資料看一下文字編碼的問題吧。
07/25 19:24, 5F

07/26 08:56, 7年前 , 6F
console沒有反法顯示次方這種的吧。如果是要畫圖的時
07/26 08:56, 6F

07/26 08:56, 7年前 , 7F
候用,那我覺得用latex比較快
07/26 08:56, 7F

07/26 08:56, 7年前 , 8F
*辦法
07/26 08:56, 8F
文章代碼(AID): #1RM2aO9l (Python)
文章代碼(AID): #1RM2aO9l (Python)