You could use a for loop with a break statement.
s = 'AAABCAA'
counter=0
firstletter=s[0]
for each in s:
if each==firstletter:
counter+=1
else:
break
print(counter)
This just returns 3.
Alternatively, you could return index of the first element of the string which is not the same as the first character of your string:
import numpy as np
s = 'AAABCAA'
firstletter=s[0]
checklist=[(each==firstletter)*1 for each in s]
print(np.where(np.asarray(checklist)==0)[0][0])
In this case, with list comprehension ([(each==firstletter)*1 for each in s]) we produce a list:
[1, 1, 1, 0, 0, 1, 1]
The value is 1 wherever the character in that spot is identical to the first character of the string.
Then np.where(np.asarray(checklist)==0)[0][0] gives you the index of the first 0 (ie the first character not identical to starting character) of this newly created list.