Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

Lecture 4 code: I'm having a hard time understanding the second line in the isPalindrome(s) function. Shouldn't the function hit the first return and then exit without computing the isPalindrome(s[1:-1])?

OpenStudy (anonymous):

Here's the code: def isPalindrome(s): """Returns True if s is a palindrome and False otherwise""" if len(s) <= 1: return True else: return s[0] == s[-1] and isPalindrome(s[1:-1])

OpenStudy (anonymous):

Actually nevermind, The two expressions are boolean and the "and" in between them acts like a logical operator.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!