Joined April 2013
·

Jeremy Swinarton

Chango
·
Toronto
·
·

This is because the % operator performs implicit type coercion as well as formatting. Behind the scenes, python is converting the value you pass to it using str().

>>> None
>>> str(None)
'None'
>>> 'this is a %s' % None
'this is a None'

This works predictably with other Python types, as well.

>>> 'this is a %s' % 123
'this is a 123'
>>> 'this is a %s' % {'abc': 123}
"this is a {'abc': 123}"

http://docs.python.org/2/library/stdtypes.html#string-formatting-operations

Achievements
59 Karma
0 Total ProTip Views