pythonの文字列
pythonの文字列に関してメモ
シングルクオートまたは、ダブルクオートで囲む
print 'python' #=>python print "python" #=>python
文字列のなかにシングルクオートを入れる
print 'I\'m python' #=>I'm python print "I'm python" #=>I'm python
文字列のなかにダブルクオートを入れる
print '"Python"' #=>"Python" print "\"Python\"" #=>"Python"
複数にまたがって記述
str_hello = "[I am python. \ you are python.]" print str_hello #=>[I am python. you are python.] str_hello = """I'm python You are python""" print str_hello #=>I'm python #=>You are python str_hello = '''I'm python You are python''' print str_hello #=>I'm python #=>You are python
raw(生)の文字列
print r'python' #=>python print r"python" #=>python print r'I\'m python' #=>I\'m python print r"I'm python" #=>I'm python print r'"Python"' #=>"Python" print r"\"Python\"" #=>\"Python\"