On Wed, 11 Feb 2009 12:57:31 -0800, bearophileHUGS wrote:
> Jason:
>> It's such a minor optimization, that you probably wouldn't see any
>> effect on your program.
>
from dis import dis
def f():
> ... return 'This is ' + 'an example.' ...
dis(f)
> 2 0 LOAD_CONST
Jason:
> It's such a minor optimization, that you probably wouldn't see any
> effect on your program.
>>> from dis import dis
>>> def f():
... return 'This is ' + 'an example.'
...
>>> dis(f)
2 0 LOAD_CONST 3 ('This is an example.')
3 RETURN_VALUE
Bye,
bea
On Feb 11, 5:16 am, bearophileh...@lycos.com wrote:
> christopher.saun...@durham.ac.uk (c d saunter):
>
> >I assume it is a feature of the compiler.<
>
> Yes it's a bug-prone antifeature that's probably a relic from C that
> doesn't have a concatenation operator among strings as Python does
> (+).
christopher.saun...@durham.ac.uk (c d saunter):
>I assume it is a feature of the compiler.<
Yes it's a bug-prone antifeature that's probably a relic from C that
doesn't have a concatenation operator among strings as Python does
(+). So in Python it saves you to use + at the cost of possible bugs.
Bruno Desthuilliers (bruno.42.desthuilli...@websiteburo.invalid) wrote:
: c d saunter a écrit :
: > I did a double take when debugging an error the other day. My
: > problem was missing out a comma when building a list of strings.
: >
: > Much to my surprise the offending code still executed to c
c d saunter a écrit :
I did a double take when debugging an error the other day. My
problem was missing out a comma when building a list of strings.
Much to my surprise the offending code still executed to cause
problems later on:
txt = 'this', 'works'
print txt
('this', 'works')
# As expect
*Literal* string concatenation has always been a part of Python :
http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation
On Wed, Feb 11, 2009 at 12:06 PM, c d saunter <
christopher.saun...@durham.ac.uk> wrote:
> I did a double take when debugging an error the other d
I did a double take when debugging an error the other day. My
problem was missing out a comma when building a list of strings.
Much to my surprise the offending code still executed to cause
problems later on:
>>> txt = 'this', 'works'
>>> print txt
('this', 'works')
# As expected
>>> txt = 'this