What exactly does the .join() method do?

后端 未结 9 2426
一向
一向 2020-11-22 10:54

I\'m pretty new to Python and am completely confused by .join() which I have read is the preferred method for concatenating strings.

I tried:

         


        
9条回答
  •  隐瞒了意图╮
    2020-11-22 11:10

    There is a good explanation of why it is costly to use + for concatenating a large number of strings here

    Plus operator is perfectly fine solution to concatenate two Python strings. But if you keep adding more than two strings (n > 25) , you might want to think something else.

    ''.join([a, b, c]) trick is a performance optimization.

提交回复
热议问题