HOW TO CONVERT A LIST TO STRING IN PYTHON
We have a list with us and need to convert it into string, there are many methods for accomplishing this.
Method 1:
li = ['hello ', 'world ', 'this ', 'is ', 'pythonpoint'] str = "" for ele in li: str +=ele print(str)
Output:
hello world this is pythonpoint
Method 2: Using .join() method
li = ['hello ', 'world ', 'this ', 'is ', 'pythonpoint'] str = "" print(str.join(li))
Output:
hello world this is pythonpoint
Method 3: Using list comprehension
li = ['hello ', 'world ', 'this ', 'is ', 'pythonpoint'] str = ''.join([str(elem) for elem in li]) print(str)
Output:
hello world this is pythonpoint
Subscribe
Login
Please login to comment
0 Discussion