How does python delete all empty characters in a string?

for example, "158.2.0.36 <-- 5.5.0.36" is converted to "158.2.0.36 <-- 5.5.0.36"


(Pdb) p s1_list
"158.2.0.36 <--   5.5.0.36"
(Pdb) p s1_list.strip()
"158.2.0.36 <--   5.5.0.36"
(Pdb) p s1_list.strip("")
"158.2.0.36 <--   5.5.0.36"
(Pdb) p s1_list.strip(" ")
"158.2.0.36 <--   5.5.0.36"
(Pdb) p s1_list.strip("") 
"158.2.0.36 <--   5.5.0.36"
(Pdb) p s1_list.strip("")
Feb.28,2021

strip is the character that deletes the beginning and end. Similarly, lstrip deletes the first part, and rstrip deletes the tail

. For more information, please see python.org/3/library/stdtypes.html-sharpstr.strip" rel=" nofollow noreferrer "> https://docs.python.org/3/lib.

.

you can use replace

>>> '158.2.0.36 <-- 5.5.0.36'.replace(' ', '')
'158.2.0.36<--5.5.0.36'
Menu