LoginSignup
0
1

More than 1 year has passed since last update.

Pythonのf文字(format済み文字列)

Last updated at Posted at 2020-07-31

f文字(format済み文字列)について

まず、これはPython3.6からなので注意してください。


a = 20
s = "あなたは{}歳".format(a)

これはPython3.6から以下のように書けます。

a = 20
s = f"あなたは{s}"

文字列の先にfをくっつける


もちろん

a = 20
s = f"あなたは{s+2}"

中括弧内で計算や、Pythonのコードも書き込める。

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