What exactly does the .join() method do?

后端 未结 9 2598
一向
一向 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 10:59

    "".join may be used to copy the string in a list to a variable

    >>> myList = list("Hello World")
    >>> myString = "".join(myList)
    >>> print(myList)
    ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
    >>> print(myString)
    Hello World
    

提交回复
热议问题