Convert list to string and string to list
Ngày đăng:
09/12/2021
Trả lời:
0
Lượt xem:
85
next prev How to convert list to string in Python?The Python list can be converted into string by using the following methods. Let's understand the following methods. Method - 1The given string iterates using for loop and adds its element to string variable. Example - Output: Hello My Name is Devansh
Method -2 Using .join() methodWe can also use the .join() method to convert the list into string. Example - 2 Output: Hello My Name is Devansh
The above method is not recommended when a list contains both string and integer as its element. Use the adding element to string variable in such scenario. Method - 3Using list comprehension Output: Peter 18 John 20 Dhanuska 26
Method - 4Using map() Output: Peter 18 John 20 Dhanuska 26
Next TopicHow to append element in the list prev next |