(original) (raw)
Because \`.format()\` is a method on an instantiated \`str\` object in e and so must return the same type so additional str methods could be stacked on after it, like \`.format(u'hi').decode()\`. Whereas the % string interpolation is a binary operation, so, like addition, where the more general type can be used for the return value, analogous to \`1 + 2.0\` returning a float.
On Wed, May 17, 2017 at 2:41 PM, Craig Rodrigues <rodrigc@crodrigues.org> wrote:
The confusion for me is why is type(e) of type str, and not unicode?and type(e) would be the same (unicode), but they are not.My intuition would lead me to believe that type(b)type(f) == unicodetype(e) == strtype(d) == strtype(c) == unicodetype(b) == unicodec = u"%s" % "hi"b = "%s" % u"hi"a = "%s" % "hi"Python 2.7I switched some code to use str.format(), I found this behavor:Hi,While cleaning up some code during Python 2 -> Python 3 porting,
=========d = "{}".format("hi")e = "{}".format(u"hi")f = u"{}".format("hi")type(a) == strCan someone clarify this for me?I understand that in Python 3, all these cases are str, so it is notas big a problem there, but I am trying to keep things working onPython 2.7.Thanks.--Craig
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/ hobsonlane%40gmail.com