python delete white spaces
sentence = ' hello apple' sentence.strip() >>> 'hello apple'
Source: stackoverflow.com
python remove whitespace from start of string
' hello world! '.strip() 'hello world!' ' hello world! '.lstrip() 'hello world! ' ' hello world! '.rstrip() ' hello world!'
Source: www.tutorialspoint.com
stripping whitespace in python
greet = ' Hello Bob ' # This is how we strip the whitespace at the beginning print(greet.lstrip()) # Output: Hello Bob # The whitespace at the end remains # This is how we strip the whitespace at the end print(greet.rstrip()) # Output: Hello Bob # The whitespace at the beginning remains # This is how we strip the whitespaces at both the beginning and at the end print(greet.strip()) # Output: Hello Bob # White spaces at beginning and at end have removed # But remember the initial string is not changed print(greet) # Output: Hello Bob
Source: www.py4e.com