HNHacker News
TopNewBestAskShowJobs

iclelland

233 karma · joined April 20, 2009

submissionscomments
iclelland··on Ask HN: Why do I have to type print "x: "+str(x) in Python?
To be fair, that's not quite the same as perl/shell-style interpolation.

In perl, "$x" pulls the value of $x from the variable namespace. In your Py2.6 example, the "{x}" format in the string has nothing to do with a variable named x; rather it references the keyword args supplied to format.

To simulate perl's

  print "x: $x";
you would

  print "x: {x}".format(x=x)
← PreviousPage 4 of 4