Re:New string formatting in Python
by nothrabannosir on Sunday January 03, 2016 @07:44PM
(#10833392)
Not the op but Im guessing just using + (which calls .__str__(), iirc?)
[ Parent
| on HN ]
Re:New string formatting in Python
by richardwhiuk on Sunday January 03, 2016 @08:10PM
(#10833480)
+ doesn't call __str__ internally.
e.g the following is an error.
a = 4
"a: " + a
You have to do: "a: " + str(a)
Re:New string formatting in Python
by barely_stubbell on Sunday January 03, 2016 @09:34PM
(#10833729)
I agree that + is likely the 4th way.
A minor correction to your comment: "+" calls the __add__ method (big surprise) - just fyi