[Tutor] Error message...

Rob Day robert.day at merton.oxon.org
Thu Aug 23 16:30:37 CEST 2012


On 23 August 2012 15:17, Victoria Homsy <victoriahomsy at yahoo.com> wrote:

>
> def isPalindrome(s):
>  if len(s) <= 1: return True
> else: return s(0) == s(-1) and isPalindrome (s[1:-1])
>
> I don't see why this wouldn't work...
>
> Many thanks in advance.
>
> Kind regards,
>
> Victoria
>

Parentheses are used for function arguments in Python, whereas square
brackets are used for slices - so the first character of s is not s(0) but
s[0].

When you say s(0) and s(-1), Python thinks you're calling s as a function
with 0 or -1 as the argument - hence, "str object is not callable".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120823/f4040000/attachment.html>


More information about the Tutor mailing list