Python Gem #14: rstrip, lstrip

When you need to remove leading and trailing whitespace such as newline characters, tabs and spaces;

strl = "     oh hi there!"
strr = "oh hi there! "
strl.lstrip() # => "oh hi there!"
strl.rstrip() # => "oh hi there!"

This is a daily series called Python Gems. Each short posts covers a detail, feature or application of the python language that you can use to increase your codes readability while decreasing its length.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.