Which is the preferred way to concatenate a string in Python?

前端 未结 12 964
眼角桃花
眼角桃花 2020-11-22 06:45

Since Python\'s string can\'t be changed, I was wondering how to concatenate a string more efficiently?

I can write like it:

s += string         


        
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 07:18

    You can use this(more efficient) too. (https://softwareengineering.stackexchange.com/questions/304445/why-is-s-better-than-for-concatenation)

    s += "%s" %(stringfromelsewhere)
    

提交回复
热议问题