How to Replace Blank Space with Hyphen in Python


In this example we will show how to replace blank spaces with hyphens in strings.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

str = input("Please input the string: ")
newStr = str.replace(" ", "-")
print("After replacing: ", newStr)

Output:

Please input the string: a b c d
After replacing: a-b-c-d
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments