2016年8月11日 星期四

formated string

"key:%s value: %s" % ("ball",100)
"name:%s, grade: %.1f" %("taco",60.66) #get 'name:taco, grade: 60.7'

s = "hi {name}~"
s.format(name = "taco") #get 'hi taco~'

s = "hi {}"
s.format(taco) # get 'hi taco'

s = "hi {0}"
s.format(taco) # get 'hi taco'

s = "hi {n1} and {n2}~"
s.format(n2 = "taco", n1 = "tom") #get 'hi tom and taco~'

raw string
a = r"\n" #is equal to '\\n'

multi-line string
a = '''hi
hi
hi
'''
gets
hi
hi
hi
a = a'''hi\n
hi\n
hi\n
'''
gets
hi\n
hi\n
hi\n


沒有留言:

張貼留言