What exactly does the .join() method do?

后端 未结 9 2544
一向
一向 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:18

    On providing this as input ,

    li = ['server=mpilgrim', 'uid=sa', 'database=master', 'pwd=secret']
    s = ";".join(li)
    print(s)
    

    Python returns this as output :

    'server=mpilgrim;uid=sa;database=master;pwd=secret'
    

提交回复
热议问题