LoginSignup
0
3

More than 1 year has passed since last update.

#python の文字列埋め込み・連結を進歩させよう ( .format から f-strings へ ) ( #初心者 向け )

Last updated at Posted at 2019-05-07

連結するやつ

first_name = 'Alice'
last_name = 'Liddel'

first_name + ' is ' + last_name
'Alice is Liddel'

なんかちょっとスマートそうな埋め込み

"{} is {}".format(first_name, last_name)
'Alice is Liddel'

辞書で渡して名前付きで埋め込むやつ

可読性が高いよね!たぶん。

"{first_name} is {last_name}".format(**{"first_name":"Alice", "last_name":"Liddell"})
'Alice is Liddell'

f-strings

first_name = "Alice"
last_name = "Liddell"
f"{first_name} is {last_name}"
'Alice is Liddell'

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
3
4

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
3