Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - String

Replace spaces with hyphens - Python Program

Example 1 :

text = "Python is fun" print(text.replace(" ", "-"))

Output

 
OUTPUT  :
Python-is-fun

Example 2 :

# Get input from the user original_string = input("Enter a string: ") # Replace spaces with hyphens modified_string = original_string.replace(" ", "-") # Print the modified string print("Original string:", original_string) print("Modified string:", modified_string)

Output

 
OUTPUT  :
Enter a string: Hello World Python
Original string: Hello World Python
Modified string: Hello-World-Python