String substitution in Python 3?

后端 未结 4 466
陌清茗
陌清茗 2021-02-05 21:20

I\'m trying to do something like this:

subs = \'world\'
\"Hello {[subs]}\"

in Python 3.

I can\'t quite figure out the syntax (having co

4条回答
  •  醉话见心
    2021-02-05 22:17

    You can use both % and format - non of them is deprecated

    subs = 'world'
    
    print ("hello %s" % subs)
    print ("hello {}".format(subs))
    print ("hello {subs}".format(**locals()))
    

    enjoY

提交回复
热议问题