You can use Python in-built methods strip(), lstrip() or rstrip() to trim whitespace from a strip as shown in the below example –
1 2 3 4 5 6 |
s = " hello world " print(s,len(s)) ## hello world 17 print(s.lstrip(),len(s.lstrip())) ## hello world 14 print(s.rstrip(),len(s.rstrip())) ## hello world 14 print(s.strip(),len(s.strip())) ## hello world 11 |