In python 2.6, why is the following line valid?
my_line = 'foo' 'bar'
and if that is valid, why isn't the following:
my_list = 1 2
The first example is string concatenation, however, the following isn't valid either (thanks god):
foo = 'foo'
bar = 'bar'
foo_bar = foo bar
This is doing string literal concatenation. As noted in the documentation, advantages include the following:
This feature can be used to reduce the number of backslashes needed, to split long strings conveniently across long lines, or even to add comments to parts of strings...
It goes on to note that this concatenation is done at compilation time rather than run time.
The history and rationale behind this, and a rejected suggestion to remove the feature, is described in PEP 3126.
my_line = 'foo' 'bar'
is string concatenation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With