How to convert list to string in Python?

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 – 1

The given string iterates using for loop and adds its element to string variable.

Example –

Output:

Hello My Name is Devansh

Method -2 Using .join() method

We 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 – 3

Using list comprehension

Output:

Peter 18 John 20 Dhanuska 26

Method – 4

Using map()

Output:

Peter 18 John 20 Dhanuska 26

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/courses/263629.html

(0)
上一篇 2022年5月30日 20:58
下一篇 2022年5月30日 20:58

相关推荐

发表回复

登录后才能评论