Pythonのダブルクォーテーションのエスケープ方法
676, 2023-06-06
Pythonでダブルクォーテーションをエスケープする
Pythonの文字列でダブルクォーテーションをエスケープするにはバックスラッシュを使います。
たとえば以下のようにです。
s = "abc\"def\"ghi" print(s) # abc"def"ghi
関連記事
Pythonのバックスラッシュ「\」の活用方法【エスケープ、複数行の式】
ちなみにシングルクォーテーションの文字列ではダブルクォーテーションはエスケープ不要です。
s = 'abc"def"ghi' print(s) # abc"def"ghi
さらにdocstring
の場合もエスケープは不要です。
s = """abc"def"ghi""" print(s) # abc"def"ghi s = '''abc"def"ghi''' print(s) # abc"def"ghi