=+ for strings
Dan Sommers
2QdxY4RzWzUUiLuE at potatochowder.com
Sun May 3 22:49:23 EDT 2020
On Sun, 3 May 2020 19:38:06 -0700 (PDT)
James Smith <bjlockie021 at gmail.com> wrote:
> I tried:
> dt=+"{:02d}".format(day)
> but I got:
> dt=+"{:02d}".format(day)
> TypeError: bad operand type for unary +: 'str'
>
> This works:
> dt=dt+"{:02d}".format(day)
>
> Why can't I do the shortcut on strings?
ITYM:
dt += "{:02d}".format(day)
Note += rather than =+ (which is parsed as an assignment operator
followed by a unary plus operator).
--
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan
More information about the Python-list
mailing list