Find a character from a string without using find method?
<p>As I am a newbie ...  not understanding why it's not working properly ?
expecting  the cause and solution and also tips
thanks</p>

<pre><code>str = "gram chara oi ranga matir poth"
find ='p'
l = len(str)
for x in range(0,l):
    if str[x]==find:         
        flag = x
        #break
if flag == x:
    print "found in index no",flag
else:
    print "not found in there"
</code></pre>

<p>Your method of searching is valid (iterating through the characters in the string).  However, your problem is at the end when you're evaluating whether or not you've found the character.  You're comparing <code>flag</code> to <code>x</code>, but when you do the comparison, <code>x</code> is <a href="http://stackoverflow.com/a/292502/1368616">out of scope</a>.  Because <code>x</code> is declared in a for loop statement, it's only defined <em>inside</em> that for loop.  So, to fix your code set an initial value for <code>flag</code> that you can check against, then change the check at the end:</p>

<pre><code>flag = None
for x in range(len(str)):
    if str[x] == find:         
        flag = x
        break  # Using break here means you'll find the FIRST occurrence of find 

if flag:
    print "found in index no",flag
else:
    print "not found in there"
</code></pre>

python string