xxxxxxxxxx
s = 'one two one two one'
print(s.replace(' ', '-'))
# Output -
# one-two-one-two-one
s = 'one two one two one'
print(s.replace(' ', ''))
# Output -
# onetwoonetwoone
xxxxxxxxxx
s = 'Some String test'
print(s.replace(' ', '-'))
# Output
# Some-String-test
xxxxxxxxxx
#user replace
string = "Hello, World!"
string = string.replace("World", "Universe")
print(string) #prints Hello, Universe!
xxxxxxxxxx
s1 = 'The theory of data science is of the utmost importance.'
s2 = 'practice'
print('The new sentence: {}'.format(s1.replace('theory', s2)))
# Ouput
# The new sentence: The practice of data science is of the utmost importance.