Remove Unwanted Space In Between A String
I wanna know how to remove unwanted space in between a string. For example: >>> a = 'Hello world' and i want to print it removing the extra middle spaces. Hello worl
Solution 1:
This will work:
" ".join(a.split())
Without any arguments, a.split()
will automatically split on whitespace and discard duplicates, the " ".join()
joins the resulting list into one string.
Post a Comment for "Remove Unwanted Space In Between A String"