21
16

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 5 years have passed since last update.

Pythonメモ:文字列に値を代入する際

Posted at

三つ方法がある。

例1:一つだけ代入
name = "juniskw"

print("Hello %s!" % name)
例2:複数代入(タプル)
f_nm = "jun"
l_nm = "iskw"

print( "Hello %s%s" % (f_nm,l_nm,) )
例3:複数代入(辞書)
f_nm = "jun"
l_nm = "iskw"

print( "Hello %(first)s%(last)s!" % {'first':f_nm,'last':l_nm,} )

いずれでも出力は同じ("Hello juniskw!")。代入する数に応じて使い分けてく感じか。

21
16
2

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
21
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?