+ 1
How to get the position of strings?
mystrng="abin(Singh(rajan" now I want to know about the position of (..how to get this? can anyone help?
6 Respuestas
+ 1
I don't know if there is a right way, but according to this, "(" is located at position 5 and 11
mystrng="abin(Singh(rajan"
position=0
for i in mystrng:
position+=1
if i == "(":
print(position-1)
#count backward
mystrng="abin(Singh(rajan"
backward=mystrng[::-1]
position=len(backward)
for i in backward:
position-=1
if i == "(":
print(position)
+ 1
index for lists start at 0. here I will change my code to represent that. there ya go, 4 and 10 now
+ 1
check my code again. first one counts forward starting with 0. second one counts backward. also, per your request it counts as if the first spot is 0. so instead of 16-1 it counts 15-0
0
it s 4 and 10 right.. starts with 0 know
0
thank you so much
0
here for i in my string:
it will initialize from 1st index character. But can we do it from backward.ie from n which is the last char in this string