Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Remove all whitespace in a string in Python

Asked by Bhagwati Dubey Jul 8, 2021 1.0K views 1 answer
Share

About this question

I want to eliminate all the whitespace from a string, on both ends, and in between words.

I have this Python code:

def my_handle(self): sentence = ' hello apple ' sentence.strip()

But that only eliminates the whitespace on both sides of the string. How python remove all spaces from string?


Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.