By HeinzKurt


2014-03-10 21:13:58 8 Comments

I really do not understand, why the code

def isIn(char, aStr): 
    ms = len(aStr)/2
    if aStr[ms] == char:
        print 'i am here now'
        return True
    elif char>aStr[ms] and not ms == len(aStr)-1:
        aStr = aStr[ms+1:]
    elif char <aStr[ms] and not ms == 0:
        aStr = aStr[0:ms]
    else:
        return False
    isIn(char, aStr)

print isIn('a', 'ab')

does keep on returning None. it prints 'i am here now', but it does not return True, just as the next line says. Why?

1 comments

@arshajii 2014-03-10 21:15:40

You probably want a return on the last line:

return isIn(char, aStr)

Without it, the function simply returns None when it terminates without seeing a return.

@HeinzKurt 2014-03-10 21:17:28

Jepp. Did not see it. And i really tried hard. Thank you!

Related Questions

Sponsored Content

27 Answered Questions

[SOLVED] What is tail recursion?

14 Answered Questions

[SOLVED] How to return multiple values from a function?

10 Answered Questions

[SOLVED] Python `if x is not None` or `if not x is None`?

0 Answered Questions

4 Answered Questions

[SOLVED] return, return None, and no return at all?

  • 2013-03-08 18:12:15
  • Clay Wardell
  • 228261 View
  • 313 Score
  • 4 Answer
  • Tags:   python null return

1 Answered Questions

Python function returns None in elif or else

4 Answered Questions

[SOLVED] not None test in Python

  • 2010-10-19 03:20:18
  • prosseek
  • 637480 View
  • 584 Score
  • 4 Answer
  • Tags:   python nonetype

1 Answered Questions

[SOLVED] Return None in Python

4 Answered Questions

[SOLVED] Whey is_leap_year returning None instead of True

  • 2016-10-13 07:51:18
  • martinbshp
  • 202 View
  • -1 Score
  • 4 Answer
  • Tags:   python

1 Answered Questions

[SOLVED] How to return a value from a recursive Python function?

Sponsored Content