119k views
4 votes
Write code that produces a string of each character separated by a -

1 Answer

2 votes

Final answer:

To create a string of each character separated by a '-', you can use the 'join' method in Python.

Step-by-step explanation:

To create a string of each character separated by a '-', you can use the 'join' method in Python. First, you need to convert the string into a list of characters using the 'list' function. Then, you can use the 'join' method to join the characters with the '-' separator. Here's an example:

string = 'Hello World'
characters = list(string)
result = '-'.join(characters)
print(result) # Output: H-e-l-l-o- -W-o-r-l-d

User Syohex
by
8.0k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories