文字列リテラル

pythonでは「"」と「'」の区別がありません。エスケープシーケンスをそのまま表示したい場合は、クォートの直前に「r」を置きます。

print "Python is an easy to learn,\tpowerful programming language."
print 'Python is an easy to learn,\tpowerful programming language.'
print r"Python is an easy to learn,\t powerful programming language."
print r'Python is an easy to learn,\tpowerful programming language.'
Python is an easy to learn,     powerful programming language.
Python is an easy to learn,     powerful programming language.
Python is an easy to learn,\t powerful programming language.
Python is an easy to learn,\t powerful programming language.


改行を含む文字列を記述する場合は、「"""」または「'''」で文字列を括ります。

print """
<html>
    <head>
        <title>hoge</title>
    </head>
    <body>
        <p>hogehogehoge</p>
    </body>
</html>
"""
<html>
    <head>
        <title>hoge</title>
    </head>
    <body>
        <p>hogehogehoge</p>
    </body>
</html>


隣接する文字列リテラルは自動的に連結されます。

print "Python is an easy to learn, " "powerful programming language."
Python is an easy to learn, powerful programming language.

リテラル同士でない場合は、「+」を使って連結します。また「*」を使うと文字列を繰り返します。

str = "Python is an easy to learn, "
print str + "powerful programming language."
print "x" * 10
Python is an easy to learn, powerful programming language.
xxxxxxxxxx


1行の文字列を複数行に分けて記述したい場合は、行末に「\」を置きます。

print "https://www.hatena.ne.jp/login?location=\
http%3A%2F%2Fd.hatena.ne.jp%2Fhogehoge%2Fedit"
https://www.hatena.ne.jp/login?location=http%3A%2F%2Fd.hatena.ne.jp%2Fhogehoge%2Fedit

インデントを揃えたい場合は、各行をクォートで、全体を「( )」で括ります。

print ("https://www.hatena.ne.jp/login?location="
       "http%3A%2F%2Fd.hatena.ne.jp%2Fhogehoge%2Fedit")