How to remove multiple spaces in a string in Python

Removing multiple spaces from a string excludes excessive whitespace so that there is only a single space between each word in the string.

Solution for How to remove multiple spaces in a string in Python : You can use str.split() to remove multiple spaces in a string Call str.split() to split str by whitespace and save the result into a list of words. Use str.join(iterable) with str as ” ” to join the words in iterable into to a single string.


how-to-remove-multiple-spaces-in-a-string-in-python