说起Python里的字符串,莫不被各大Python大佬们所熟知,不过今天鱼头还是要班门弄斧,来研究下字符串这个东东。
1:Python中的字符串拼接
说起字符串拼接,方法可多了去了,比方说最简单的:
a = 'hello'
b = ' '
c = 'world'
print(a+b+c)
#'hello world'
但是如果内容很多,就尴尬了:
name = 'Mrfish'
address = 'Changchun,China'
phone_number = '123 1234 1234'
num = 4
print('hello!'+name+'.Your address is:'+address+'.Your phone number is:'+phone_number+'.Your number is:'+str(num)+'.')
'''output:
"hello!Mrfish.Your address is:Changchun,China.Your phone number is:123 1234 1234.Your number is:4."
'''
可以说是很反智了……
所以,这时百分号“%”就派上了用场。