1.+号连接

a="hello,"
b="world!"
c=a+b
print(c)

有一点需要注意的是,字符串类型是不可变的,所以每一次应用加号连接字符串都会生成一个新的字符串,连接多个字符串时,效率低下就是必然的了。

2.join()连接

a="hello,"
b="world!"
c=''.join([a,b])
print(c)

连接大量字符串时,join是性能最好的选择。

相关文章:

  • 2021-10-11
  • 2021-12-13
  • 2021-06-15
猜你喜欢
  • 2021-08-27
  • 2021-07-18
  • 2021-07-20
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
相关资源
相似解决方案