-1

This is my string "INDUSTRIAL, PARKS, PROPERTY" I want to delete the spaces trailing parks, property. I want the output as "INDUSTRIAL,PARKS,PROPERTY"

1
  • If you search in your browser for "Python remove spaces from line", you'll find references that can explain this much better than we can manage here. Commented Oct 18, 2019 at 16:34

1 Answer 1

0

For your example you can do:

strr = "INDUSTRIAL, PARKS, PROPERTY"
','.join(strr.split(', '))

Otherwise if you have something like:

strr = "INDUSTRIAL, PARKS,    PROPERTY"
','.join([s.strip() for s in strr.split(', ')])
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the answer but how do I remove the ending space also? strr = "INDUSTRIAL, PARKS,PROPERTY " (note the ending space after Property)
use .strip() on the initial string

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.