>>> " xyz ".rstrip()
' xyz'
There is more about rstrip in the documentation.
>>> " xyz ".rstrip()
' xyz'
There is more about rstrip in the documentation.
You can use strip() or split() to control the spaces values as the following, and here is some test functions:
words = " test words "
# Remove end spaces
def remove_end_spaces(string):
return "".join(string.rstrip())
# Remove first and end spaces
def remove_first_end_spaces(string):
return "".join(string.rstrip().lstrip())
# Remove all spaces
def remove_all_spaces(string):
return "".join(string.split())
# Remove all extra spaces
def remove_all_extra_spaces(string):
return " ".join(string.split())
# Show results
print(f'"{words}"')
print(f'"{remove_end_spaces(words)}"')
print(f'"{remove_first_end_spaces(words)}"')
print(f'"{remove_all_spaces(words)}"')
print(f'"{remove_all_extra_spaces(words)}"')
output:
" test words "
" test words"
"test words"
"testwords"
"test words"
i hope this helpful .
How do I remove the whitespace at the end of a string?
Help removing whitespace at end of output
Is there a way to remove whitespace between characters in python?
Spaces, or end of line
I typed up the code :
int1 = int(input(''))
int2 = int(input(''))
if int1 > int2:
print('Second integer can\'t be less than the first')
while int1 <= int2:
print(int1, end = ' ')
int1 += 5
such that when I input -15 and 10 (for example), it will output:
-15 -10 -5 0 5 10
There's whitespace after the 10, however, and I'm supposed to remove it. How do I accomplish this?