次の構文はPython 3.6のf-stringでサポートされていませんか?私はF-文字列を結合線場合は、置換は発生しません。f-stringでライン結合がサポートされていませんか?
SUB_MSG = "This is the original message."
MAIN_MSG = f"This longer message is intended to contain " \
"the sub-message here: {SUB_MSG}"
print(MAIN_MSG)
リターン:
This longer message is intended to contain the sub-message here: {SUB_MSG}
私はライン-加入削除する場合:
SUB_MSG = "This is the original message."
MAIN_MSG = f"This longer message is intended to contain the sub-message here: {SUB_MSG}"
print(MAIN_MSG)
を期待どおりに動作しますが:
This longer message is intended to contain the sub-message here: This is the original message.
PEP 498は、バックスラッシュ内F-文字列が明示サポートされていません。あなたがそれらを使用することはできませんので
エスケープシーケンスを
バックスラッシュは、例えば、 F-文字列の表現部分の内側に表示されない場合がありますF-文字列内の引用符 をエスケープします
>>> f'{\'quoted string\'}'
は、ラインジョインF-STRの発現部分の内側」とみなされていしたがってサポートされていませんか?
はない別の場所で、F-文字列*、*の表現部分内ではサポートされません。また、2番目の文字列リテラルに 'f'を追加するだけです。これは他の文字列接頭辞がどのように機能するかと一貫しています: 'len(r" \\ "" \\ ")== 3'。 – Ryan