pythonで変数を文字列に組み込むときにわかりやすく書ける方法を備忘録として残しておきます
例えば、通常下のような記述がありますが""や+が多く煩雑になってしまう恐れがあります。
name="太郎"
print("私の名前は"+name+"です")
これをf""で全体の文をくくり、変数を{}で表すことができます
name="太郎"
print(f"私の名前は{name}です")
こちらの方が分かりやすいのではないのでしょうか。もしよかったら使ってみてください
Go to list of users who liked
More than 3 years have passed since last update.
pythonで変数を文字列に組み込むときにわかりやすく書ける方法を備忘録として残しておきます
例えば、通常下のような記述がありますが""や+が多く煩雑になってしまう恐れがあります。
name="太郎"
print("私の名前は"+name+"です")
これをf""で全体の文をくくり、変数を{}で表すことができます
name="太郎"
print(f"私の名前は{name}です")
こちらの方が分かりやすいのではないのでしょうか。もしよかったら使ってみてください
Register as a new user and use Qiita more conveniently
Go to list of users who liked