How to delete spaces in strings using strip () in Python
This article describes how to use strip () to delete spaces in strings in Python. It is a basic knowledge of getting started with Python. For more information, see
The strip () method returns a copy of all characters removed from the start and end of the string (default space character.
Syntax
The following is the syntax of the strip () method:
?
Parameters
Chars -- character-the string from the start or end is removed.
Return Value
This method returns a copy of all characters removed from the start and end of the string (default space character.
Example
The following example shows how to use the strip () method.
?
1 2 3 4 |
#! /Usr/bin/python Str = "0000000 this is string example... wow !!! 0000000 "; Print str. strip ('0 '); |
When we run the above program, it will produce the following results:
?
1 |
This is string example... wow !!! |