"Why do we need to remove those spaces"
Spaces to the human mind is a gap between text that allows us to identify words in a sentence.
So we tend to ignore it.
But a space to a computer is a text character, just as important as a letter, number or punctuation mark.
Just because we can't see it does not mean it doesn't exist.
Let me attach a little code which may help you understand further
This code tries to make a triangle out of stars. But oh no! There’s an error in there somewhere - it outputs all the stars on one line, instead of separate lines.
Fix the code to output a triangle of stars that has 4 rows.
Print("* \n** n\*** n\**** n\****")