I'm super new to any sort of programming, so forgive my ignorance for not knowing how to do something that seems so simple.
All I'd like to do is take any array of strings (call it name), let's say:
["John", "Charles", "Smith"]
and remove it from the list and turn it into a string:
John Charles Smith
I can't seem to get my head around this and couldn't find a similar post.
You can concatenate a list of strings into a single string with the string method, join() . Call the join() method from 'String to insert' and pass [List of strings] . If you use an empty string '' , [List of strings] is simply concatenated, and if you use a comma , , it makes a comma-delimited string.
Using StringBufferCreate an empty String Buffer object. Traverse through the elements of the String array using loop. In the loop, append each element of the array to the StringBuffer object using the append() method. Finally convert the StringBuffer object to string using the toString() method.
You can go from a list to a string in Python with the join() method. The common use case here is when you have an iterable—like a list—made up of strings, and you want to combine those strings into a single string.
Using the tuple() built-in function An iterable can be passed as an input to the tuple () function, which will convert it to a tuple object. If you want to convert a Python list to a tuple, you can use the tuple() function to pass the full list as an argument, and it will return the tuple data type as an output.
Just use:
" ".join(["John", "Charles", "Smith"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With