アットウィキロゴ

文字列

ヒアドキュメント

"""で文字列を囲みます。文末に\を記述すると、直後の改行は無視されます。
# ヒアドキュメントで代入
text = """\
This is
a example \
of here document."""
print text # This is\na example of here document.

先頭と末尾の空白文字の削除

strip() を使います。
# 先頭にタブと空白、末尾に改行がある文字列の例
text = "\t strip\n"
# 先頭と末尾の空白文字の削除
print text.strip() #=> strip
最終更新:2012年04月04日 21:30