xxxxxxxxxx
s = " hello world "
print(s.strip())
xxxxxxxxxx
# define a string with leading and trailing whitespace
my_string = ' Hello, world! '
# remove the leading and trailing whitespace
result = my_string.strip()
print(result) #prints Hello, world!
# remove the leading whitespace
result = my_string.lstrip()
print(result) #prints Hello, world!
# remove the trailing whitespace
result = my_string.rstrip()
print(result) #prints Hello, world!
xxxxxxxxxx
#If you want to remove LEADING and ENDING spaces, use str.strip():
sentence = ' hello apple'
sentence.strip()
>>> 'hello apple'
xxxxxxxxxx
Use the lstrip() method
>>> name = ' Steve '
>>> name
' Steve '
>>> name = name.lstrip()
>>> name
'Steve '
xxxxxxxxxx
vals_inp=input()
list_set = list(vals_inp)
vals = [x for x in list_set if x != ' ']
set_vals = set(vals)