-3

#the list to make an string format a = ['h','e','l','l','o','','w','o','r','l','d','!']

#wanted output

hello world!

  • 2
    Does this answer your question? [How to concatenate items in a list to a single string?](https://stackoverflow.com/questions/12453580/how-to-concatenate-items-in-a-list-to-a-single-string) – Mr. T Jan 03 '22 at 17:07
  • See: [`str.join()`](https://docs.python.org/3/library/stdtypes.html#str.join) – 001 Jan 03 '22 at 17:07

1 Answers1

-1

It seems some suggestions was given above about how to solve this problem. An approach that can be taken though is creating a empty string variable and concatenating all the characters from the given character list to the string variable. For example,

a = ['h','e','l','l','o','','w','o','r','l','d','!']
temp_string = ""
for eachChar in a:
    temp_string += eachChar
print(temp_string)

The output of this result to

helloworld!

This is due to the null character between hello and world. If the null character was instead a space such as ['h','e','l','l','o',' ','w','o','r','l','d','!'], the output will result to what you have displayed above.