Logic Building
# Take string input
s = input("Enter a string: ")
# Remove spaces
no_spaces = s.replace(" ", "")
print(f"Without spaces: {no_spaces}")Output
Enter a string: Hello World Without spaces: HelloWorld
Use replace() to remove spaces.
Key Concepts:
- replace(" ", "") removes all spaces
- Returns new string
- Original unchanged