概述:
Python中可以将两个或多个字符串拼接起来,组成新的字符串
1. + 加法运算符
代码:
str1 = 'hello'
print(str1+' '+'world!')
输出:
hello world!
2. join()将列表转化为字符串
代码:
str2 = ['hello','world','everyone']
print('*'.join(str2))
print(' '.join(str2))
输出:
hello*world*everyone
hello world everyone
3、format() 字符串中{}数量和format()参数个数必须一致
代码:
str3 = '{} {}!'.format('hello','world')
print(str3)
输出:
hello world!
4、%s 格式占位符
代码:
str4 = '%s,%s!'%('hello','world')
print(str4)
输出:
hello,world!