Pythonでシングルクォーテーション・ダブルクォーテーションを文字列として取り扱う(エスケープ)する方法

Pythonで文字列内にシングルクォーテーション(’)またはダブルクォーテーション(")を文字列として含めるには、エスケープ文字を使用します。以下にそれぞれの場合のエスケープ方法を示します。

  1. シングルクォーテーションを文字列として扱う場合:
python
string_with_single_quote = 'This is an example of a single quote: ''
  1. ダブルクォーテーションを文字列として扱う場合:
python
string_with_double_quote = "This is an example of a double quote: ""

未分類

Posted by ぼっち