On Sun, Aug 3, 2008 at 8:29 PM, Antoine Pitrou <[EMAIL PROTECTED]> wrote:
> In many cases there is no runtime concatenation cost.
>
>>>> def f():
> ...  return "first" + "second"
> ...
>>>> import dis
>>>> dis.dis(f)
>  2           0 LOAD_CONST               3 ('firstsecond')
>              3 RETURN_VALUE

The "many cases" only extends to strings whose combined length is less
than 20 characters:

>>> dis.dis(lambda : "1234567890123456789" + "0")
  1           0 LOAD_CONST               2 ('12345678901234567890')
              3 RETURN_VALUE
>>> dis.dis(lambda : "1234567890123456789" + "01")
  1           0 LOAD_CONST               0 ('1234567890123456789')
              3 LOAD_CONST               1 ('01')
              6 BINARY_ADD
              7 RETURN_VALUE

Adjacent string concentation works on arbitrary length string constants:

>>> dis.dis(lambda : "12345678901234567890"  "12345678901234567890")
  1           0 LOAD_CONST               0
('1234567890123456789012345678901234567890')
              3 RETURN_VALUE
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to