0
1

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 1 year has passed since last update.

[Python] Stringと数字を一緒に出力(f-String)

Posted at

今日は簡単にf-Stringの使い方を勉強しましょう。


suji = 12

print("sujiは " + suji + "です。")   ## error

今までintとかfloatをstringと一緒にprint()関数の中で使うためにintをStringに変更して少し面倒くさいでした

suji = 12

print("sujiは " + str(suji) + "です。")   ## sujiは 12です。


しかしf-Stringを使ったらもっと簡単にできます。
まずダブルクォーテーションの前にfを付きます。
そして使いたいintとかfloat関数名を{}の中に書きます。

suji = 12

print(f"sujiは {suji}です。" ## sujiは 12です。

これでもっと簡単にprint関数を使えます。
以上です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?