remove whitespace from start of string in python

To remove whitespace from the start of a string in Python, you can use the lstrip() string method. Here's an example:

main.py
my_string = "  hello world"
my_string = my_string.lstrip()
print(my_string)  # Output: "hello world"
101 chars
4 lines

The lstrip() method removes any whitespace characters, including spaces, tabs, and newline characters, from the start (left side) of the string. If you want to remove whitespace from the end or both ends of the string, you can use the rstrip() and strip() string methods, respectively.

gistlibby LogSnag