LoginSignup
3
1

More than 1 year has passed since last update.

Pythonのf文字列の便利な使い方

Posted at

f文字列の知らない使い方があったためメモ。

変数xの値をx = 1のように変数名 = 変数の値と出力したいときに、

x = 1
print(f"x = {x}")

とやってもよいですが、Python 3.8以上では

x = 1
print(f"{x = }")

とすると

x = 1

と出力されるようです。

3
1
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
3
1