{"id":10195,"date":"2021-09-30T12:00:58","date_gmt":"2021-09-30T06:30:58","guid":{"rendered":"https:\/\/python-programs.com\/?p=10195"},"modified":"2021-11-22T18:34:39","modified_gmt":"2021-11-22T13:04:39","slug":"python-program-to-take-in-a-string-and-replace-every-blank-space-with-hyphen","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-take-in-a-string-and-replace-every-blank-space-with-hyphen\/","title":{"rendered":"Python Program to Take in a String and Replace Every Blank Space with Hyphen"},"content":{"rendered":"

Strings in Python:<\/strong><\/p>\n

A string is one of the most frequent data types in any computer language. A string is a collection of characters that can be used to represent usernames, blog posts, tweets, or any other text content in your code. You can make a string and assign it to a variable by doing something like this.<\/p>\n

given_string='btechgeeks'<\/code><\/p>\n

Strings are considered immutable in Python, once created, they cannot be modified. You may, however, construct new strings from existing strings using a variety of approaches. This form of programming effort is known as string manipulation.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string = hello this is BtechGeeks<\/pre>\n

Output:<\/strong><\/p>\n

The original string before modification = hello this is BtechGeeks\r\nThe new string after modification = hello-this-is-BtechGeeks<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string = files will be upload to a folder you can read those files in the program folder<\/pre>\n

Output:<\/strong><\/p>\n

Enter some random string = files will be upload to a folder you can read those files in the program folder\r\nThe original string before modification = files will be upload to a folder you can read those files in the program folder\r\nThe new string after modification = files-will-be-upload-to-a-folder-you-can-read-those-files-in-the-program-folder<\/pre>\n

Program to Take in a String and Replace Every Blank Space with Hyphen<\/h2>\n

Below are the ways to scan the string and replace every blank space with a hyphen in Python.<\/p>\n