Remove Whitespace from String (Strip Methods) Dry Run in PYTHON

Remove Whitespace from String (Strip Methods) is an interactive PYTHON dry run visualizer from the Strings programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Remove Whitespace from String (Strip Methods) Program Code

# Python program to demonstrate strip methods
text = "   Hello World!   \n\t"

print("Original:", repr(text))
print("strip() - removes from both ends:", repr(text.strip()))
print("lstrip() - removes from left:", repr(text.lstrip()))
print("rstrip() - removes from right:", repr(text.rstrip()))

# Custom character stripping
custom_text = "***Hello***"
print("\nCustom stripping:")
print("Original:", repr(custom_text))
print("strip('*'):", repr(custom_text.strip('*')))
print("lstrip('*'):", repr(custom_text.lstrip('*')))
print("rstrip('*'):", repr(custom_text.rstrip('*')))

# Practical example: cleaning user input
user_input = input("\nEnter a string with spaces: ")
cleaned = user_input.strip()
print("Cleaned input:", repr(cleaned))
print("Length before:", len(user_input), "after:", len(cleaned))

View the complete Strings programs page.

Program Console Remove Whitespace from String (Strip Methods) Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.