From 1cc6f9361d89b697903f6e640e10bebc4cbeae96 Mon Sep 17 00:00:00 2001 From: "Kaz Saita(raspi4)" Date: Sat, 23 Mar 2024 20:15:20 +0900 Subject: [PATCH] sync notes(auto) --- content/20240323192523 pythonのf-string.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 content/20240323192523 pythonのf-string.md diff --git a/content/20240323192523 pythonのf-string.md b/content/20240323192523 pythonのf-string.md new file mode 100644 index 0000000..4797adb --- /dev/null +++ b/content/20240323192523 pythonのf-string.md @@ -0,0 +1,10 @@ +# 20240323192523 pythonのf-string +#python +## 基本的な使いかた +`{}`をplacefolderとして文字列に +"{} {} {}".format(a, b, c) とかやって変数を埋めこめる機能。 [rubyの式展開](https://docs.ruby-lang.org/ja/latest/doc/spec=2fliteral.html#exp) 、[javascriptの テンプレートリテラル](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Template_literals)などにも近いが、 +細かい書式指定なども可能なため、Cの[printfのフォーマット指定](https://ja.wikipedia.org/wiki/Printf#%E6%9B%B8%E5%BC%8F%E5%8C%96%E6%96%87%E5%AD%97%E5%88%97)が一番近いかもしれない。といいつつ、現状だとそこまで色々使っていないかも。 +参考サイトの説明が詳しい。 + +## Ref. +- [Pythonのf文字列(フォーマット済み文字列リテラル)の使い方 | note.nkmk.me](https://note.nkmk.me/python-f-strings/)