Reputation: 39
So this is it what it would look like
string1 = "This is my string"
output would be:
string1 = "Thisismystring"
Upvotes: 0
Views: 32
Reputation: 124
>>> def foo(s: str):
... return s.replace(' ', '')
...
>>> print(foo("This is my string"))
Thisismystring
>>> def foo(s: str):
... return ''.join(s.split(' '))
...
>>> print(foo("This is my string"))
Thisismystring
Upvotes: 2
Reputation: 9503
Try this
import re
string1 = "This is my string"
output = re.sub(r'\s', '', string1)
# or
output= string1.replace(" ","")
print(output)
Upvotes: 0