How to convert a list to string in Python

Configurare noua (How To)

Situatie

Solutie

Pasi de urmat

def listToString(elements):

# initialize an empty string
str = “”

# traverse in the string
for element in elements:
str += element

# return string
return str

elements = [‘Just’, ‘a’, ‘test’]
print(listToString(elements))

Output:

Justatest

Tip solutie

Permanent

Voteaza

(16 din 32 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?