Quantcast
Channel: いろいろ備忘録日記
Viewing all articles
Browse latest Browse all 1457

Pythonメモ-120 (f-stringで = を付与して出力)(python3.8, デバッグ用, )

$
0
0

概要

Python 3.8 で、f-string に以下のような機能が追加されていたのを、すっかり忘れていたので、ついでにここにメモメモ。。。

docs.python.org

{x=}ってすると、x=1のように出力してくれる機能です。めっちゃ便利ですねー。

サンプル

"""Python 3.8 にて導入された f-string での {xxx=} 表記についてのサンプルです.REFERENCES:: http://bit.ly/2NlJkSc"""from trypython.common.commoncls import SampleBase


classSample(SampleBase):
    """f-string での {xxx=} 表記についてのサンプルです."""defexec(self):
        """処理を実行します."""# ------------------------------------------------------------# f-string debugging specifier## f-string 内にて {xxx=} と イコールを付与した場合に# "xxx=値" を出力してくれるようになった。## {xxx = } とすると、"xxx = 値"と表示してくれる## フォーマット指示子も付与できる.# {xxx = :>10}# ------------------------------------------------------------
        s1 = "hello"
        s2 = "world"
        s3 = "hoge"print(f"{s1=}\t{s2 = }\t{s3=:>10}")


defgo():
    """サンプルを実行します."""
    obj = Sample()
    obj.exec()

実行すると以下のようになります。

$ python -m trypython

ENTER EXAMPLE NAME: py38_fstring_debug


[START]==== py38_fstring_debug ====s1='hello'      s2 ='world's3=      hoge
[END  ]==== py38_fstring_debug ====


DONE

参考資料


過去の記事については、以下のページからご参照下さい。

  • いろいろ備忘録日記まとめ

devlights.github.io

サンプルコードは、以下の場所で公開しています。

  • いろいろ備忘録日記サンプルソース置き場

github.com

github.com

github.com


Viewing all articles
Browse latest Browse all 1457

Trending Articles