How to remove leading and trailing whitespaces from a string in Python

1 Answer

0 votes
s = "          python java php c c++    "
 
print(len(s))

s = s.strip()

print(len(s))

print(s)
 
 
 
 
 
'''
run:
 
35
21
python java php c c++
 
'''

 



answered Apr 19, 2021 by avibootz
...