Open this example in the interactive library
Source code
text = ' hello Python '
print(' '.join(text.split()))Sample output
hello Python

Normalize whitespace. A self-contained example using the Python standard library.
Open this example in the interactive library
text = ' hello Python '
print(' '.join(text.split()))hello Python