[Python-3000] Immutable bytes type and dbm modules

Adam Olsen rhamph at gmail.com
Wed Aug 8 05:52:31 CEST 2007


On 8/7/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> So concatenating mutable and immutable should give the
> same result as concatenating two immutables, i.e. an
> immutable. If you need to add something to the end of
> your buffer, while keeping it mutable, you use extend().
>
> This gives us
>
>    immutable + immutable -> immutable
>    mutable + immutable -> immutable
>    immutable + mutable -> immutable
>    mutable + mutable -> mutable  (*)

>>> () + []
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate tuple (not "list") to tuple

Less confusing to prohibit concatenation of mismatched types.  There's
always trivial workarounds (ie () + tuple([]) or .extend()).

-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list