I'm new to Python, but I had a simple question. I know that I can use lstrip() to strip leading whitespaces/tabs from a string. But lets say I have a string str:
str = '+ 12 3'
I want the result to be
'+12 3'
I wanted to achieve this by calling lstrip on a substring of the original string:
str[1:] = str[1:].lstrip()
But I get the following error:
Traceback (most recent call last):
File "ex.py", line 51, in <module>
print(Solution().myAtoi(' 12 3'))
File "ex.py", line 35, in myAtoi
str[x:] = str[x:].lstrip()
TypeError: 'str' object does not support item assignment
Is there a way to achieve this using lstrip()? Or should I look into another way of doing this?
For the record, this is just a leetcode practice problem, and I'm attempting to write it in Python to teach myself - some friends say its worth learning
Thanks! :D