0
1

More than 3 years have passed since last update.

python 文字列の連結の工夫

Posted at

pythonで変数を文字列に組み込むときにわかりやすく書ける方法を備忘録として残しておきます
例えば、通常下のような記述がありますが""や+が多く煩雑になってしまう恐れがあります。

name="太郎"
print("私の名前は"+name+"です")

これをf""で全体の文をくくり、変数を{}で表すことができます

name="太郎"
print(f"私の名前は{name}です")

こちらの方が分かりやすいのではないのでしょうか。もしよかったら使ってみてください

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