文字列(その1)
s = 'test'
print(s)
test
print('hello')
hello
print("hello")
hello
print("I don't know")
I don’t know
print('I don\'t know')
I don’t know
print('say "I don\'t know"')
say “I don’t know”
print("say \"I don't know\"")
say “I don’t know”
print('hello \nHow are you?')
hello
How are you?
r —- rowデータ
print(r'C:\name\name')
C:\name\name
print("""
line1
line2
line3
""")
line1
line2
line3
print("##############")
print("""\
line1
line2
line3\
""")
print("##############")
########
line1
line2
line3
##############
print('Hi.' * 3 + 'Mike.)
Hi.Hi.Hi.Mike.
print('Py''thon')
Python
print('Py' + 'thon')
Python
リテラル と 変数の連結
prefix = 'Py'
print(prefix + 'thon')
Python
パレンティス と バックスラッシュ
s = ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'bbbbbbbbbbbbbbbbbbbbbbb')
print(s)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbb
s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\
'bbbbbbbbbbbbbbbbbbbbbbb'
print(s)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbb
コメント