Pythonでは文字列を""
または''
でくくることで他の型と区別しますが、文字列自体に"
を含めたい場合、""
の中に"
をそのまま書くと構文エラーになります。
"と'を併用する方法

つまりこういう状態になります。
""
で閉じた文字列の中に、そのまま"
を入れることはできません。
'
で閉じた場合も同様。
ただし、
""
で閉じた文字列の中に"
を入れるか、逆に''
で閉じてその中に"
を入れた場合はエラーになりません。\を前に置く方法
#python
print("She says \"hello\"")
もうひとつの解決策としては、文字列中に含めたい
"
または'
の前に\(英文キーだと半角のバックスラッシュ)を置きます。この場合、同じ記号で閉じていても問題ありません。
実行結果です。

Python操作方法、関数・メソッドリファレンス
使用用途別にまとめたPythonリファレンスページです。
初期準備、基本概念
ダウンロード、インストール、起動
ShellとEditor、保存、実行
保存したPythonの起動
コメント、docstring、行またぎ
コメント、...
コメント