Is there a Python equivalent to Ruby's string interpolation?

前端 未结 9 1170
攒了一身酷
攒了一身酷 2020-11-22 17:04

Ruby example:

name = \"Spongebob Squarepants\"
puts \"Who lives in a Pineapple under the sea? \\n#{name}.\"

The successful Python string co

9条回答
  •  深忆病人
    2020-11-22 17:47

    I've developed the interpy package, that enables string interpolation in Python.

    Just install it via pip install interpy. And then, add the line # coding: interpy at the beginning of your files!

    Example:

    #!/usr/bin/env python
    # coding: interpy
    
    name = "Spongebob Squarepants"
    print "Who lives in a Pineapple under the sea? \n#{name}."
    

提交回复
热议问题