0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonのモジュールを使って添字、指数を表示

Last updated at Posted at 2018-08-02

##HTMLのタグ
HTMLにはsubscriptタグ、superscriptタグが存在し、それぞれ添字、指数を表示するためのタグです。

今回はそれをpythonで出力時に使いたいと思います。
使い道は、添え字、指数を使って文字列をわかりやすく表示することくらいだとは思いますが。

#コード

#モジュールのインポート
from IPython.display import HTML

#HTMLコードを記述
code = """
str<sub>添え字</sub>
str<sup>指数</sup>
"""
#表示
HTML(code)

#複数回使う場合

from IPython.display import HTML
def sub(sub):
    sub = "<sub>" + str(sub) + "</sub>"
    return sub
def sup(sup):
    sup = "<sup>" + str(sup) + "</sup>"
    return sup

また、上記のように関数を定義すると、

equation = "6 = log" + sub(2) + "8" + sup(2)
HTML(equation)

とコードを記述すると
6 = log282
と表示されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?