Python/Django: How to remove extra white spaces & tabs from a string?

后端 未结 6 2150
天命终不由人
天命终不由人 2020-12-29 21:59

I\'m building a website with Python/Django. Users submit tags. Each tag can contain multiple words. Each tag has an ID number. I want to make sure tags that are formatted sl

6条回答
  •  遥遥无期
    2020-12-29 23:00

    There could be many white spaces like below:

    var = "         This      is the example  of how to remove spaces   "
    

    Just do simple task like, use replace function:

    realVar = var.replace(" ",'')
    

    Now the outpur would be:

    Thisistheexampleofhowtoremovespaces 
    

    Just Chill......... :-)

提交回复
热议问题