What is this syntax ?
Roy Smith
roy at panix.com
Sun Jun 19 11:39:44 EDT 2011
In article <4dfe10d1$0$28053$426a34cc at news.free.fr>,
candide <candide at free.invalid> wrote:
> OK, thanks for your explanation, it was just stringisation !
>
>
> I erroneously focused on
>
> +x+
>
> as a kind of placeholder unknown to me, instead of left and right
> concatenations ;)
>
> It would be more readable for me if it were edited
>
> >>> print '"' + x + '"' # better spacing
> "foo"
> >>>
>
> or with string formatting :
>
> >>> x="foo"
> >>> print '"%s"' %x
> "foo"
> >>>
This is one of the (very) few places PHP wins over Python. In PHP, I
would write this as
print "'$x'"
which seems easier to read than any of the Python versions. Of course,
sharp-eyed readers will notice that I inverted the single and double
quotes because
print '"$x"'
doesn't work. If you really wanted to replicate the output exactly, you
would have to do
print "\"$x\""
by which time you'd probably run back to writing it in Python :-)
More information about the Python-list
mailing list