I just discovered what I thought was a typo but Python accepts it.
foo = {'a': 'b'}
foo.get('a'"")
returns 'b'
. Where in Python is 'a'""
defined as a valid parameter to a function?
I just discovered what I thought was a typo but Python accepts it.
foo = {'a': 'b'}
foo.get('a'"")
returns 'b'
. Where in Python is 'a'""
defined as a valid parameter to a function?
Python concatenates all consecutive strings. It doesn't matter if that's in a function or elsewhere.
See the String literal concatenation section of the reference documentation:
Multiple adjacent string literals (delimited by whitespace), possibly using different quoting conventions, are allowed, and their meaning is the same as their concatenation.
This is done at the parsel level; the final bytecode stores just the one string object. See What is under the hood of x = 'y' 'z' in Python?
The feature was copied from C. From a (failed) proposal to remove the feature:
Many Python parsing rules are intentionally compatible with C. [...] In C, implicit concatenation is the only way to join strings without using a (run-time) function call to store into a variable.
The feature is very useful when producing long strings:
long_value = (
'The quick brown fox jumped over the lazy fox and kept '
'the string within the 80 character boundary.'
)