Ejemplo 2 usando join () para convertir lista en string con python. Este método solo sirve cuando se tiene una lista que solo contiene strings, el método. join () de los strings une las palabras de la lista poniendo el string inicial en medio de cada una de las palabras, el siguiente ejemplo muestra como ocupar este método: ['pfb', 11. 2, 11, 'python'] output string is:
Pfb 11. 2 11 python. In the above example, we can see that an extra space has been added at the end of the string. We can use the rstrip() method to remove the extra space from the string.
An alternative way to convert a list to string in python is to use the join() method. The join method requires the str data type as the given parameters. Therefore, if you try to join the int type list, you will get the typeerror
Como se muestra en el ejemplo, la cadena , una cadena vacía, se inserta entre los elementos de la lista. Si quiere que se añada un espacio entre los elementos, entonces debe utilizar. El método join requiere el tipo de datos str como los.
Let’s see various ways we can convert the list to string. The first method is to assign a list and traverse each element using for loop and adding it to an empty string. S = ['geeks', 'for', 'geeks'] str1 = .