Is line-joining unsupported by f-strings?
You have to mark both strings as f
-strings to make it work, otherwise the second one is interpreted as normal string:
SUB_MSG = "This is the original message."
MAIN_MSG = f"test " \
f"{SUB_MSG}"
print(MAIN_MSG)
Well, in this case you could also just make the second string the f-string because the first one doesn't contain anything to interpolate:
MAIN_MSG = "test " \
f"{SUB_MSG}"
Note that this affects all string-prefixes not just f-strings:
a = r"\n" \
"\n"
a # '\\n\n' <- only the first one was interpreted as raw string
a = b"\n" \
"\n"
# SyntaxError: cannot mix bytes and nonbytes literals
Try this (note the extra “f” on the continuation line):
SUB_MSG = "This is the original message."
# f strings must be aligned to comply with PEP and pass linting
MAIN_MSG = f"This longer message is intended to contain " \
f"the sub-message here: {SUB_MSG}"
print(MAIN_MSG)