-4

How do I strip character 'A' from the beginning of a string if the string starts with 'A'?

"AsomethingAsomething" output should be "somethingAsomething"
"somethingAsomething" output should be "somethingAsomething"

(Using Python 3.x)

clacke
  • 7,688
  • 6
  • 46
  • 48
MarcoBuster
  • 1,145
  • 1
  • 13
  • 21
  • Have a look at [lstrip](https://docs.python.org/2/library/string.html#string.lstrip) -> `'AsomethingAsomethingAsomething'.lstrip('A')` – Simon Fraser Mar 30 '16 at 10:48
  • What did u try so far?..Have u heard about string slicing? – Iron Fist Mar 30 '16 at 10:48
  • 1
    Possible duplicate of [Is there a way to substring a string in Python?](http://stackoverflow.com/questions/663171/is-there-a-way-to-substring-a-string-in-python) – EluciusFTW Mar 30 '16 at 11:03

3 Answers3

2

Try this:

s = "AsomethingAsomethingAsomething"

s[s.find('A')+1:]

s.lstrip('A')
gorros
  • 1,411
  • 1
  • 18
  • 29
1

Combine some logic and str methods and slice:

if some_string.startswith('A'):
    some_string = some_string[1:]

Or even better, just use some_string = some_string.lstrip('A') as proposed in the comments.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
0

with lstrip

string = "AsomethingAsomethingAsomething"
string.lstrip('A')
Adarsh Dinesh
  • 106
  • 12