Python Practice › String Programs › Program 40
Split and join a string
Write a Python program to split a string into words and join them with “-“.
Input
"Hello world"
Output
['Hello', 'world'] Hello-world
Approach
split()then"-".join().
Solution
parts = "Hello world".split()print(parts)print("-".join(parts))Output
['Hello', 'world'] Hello-world
Learn the concept
New to this topic? Read the lesson, then come back.