Reputation: 117
Why am I getting an error builtin_function_function_or_method object is not subscriptable and how can i make a string into a list so I can index into the string?
s = input("Please enter a word: ")
s = s.lower
Pal = True
def recpal(s):
if Pal == False:
return(False)
else:
return(True)
def main():
y = recpal(s)
first_char = 0
last_char = -1
if s[first_char] != s[last_char]:
print("It is not a Palindrome")
i = 0
while i >= n[-1]:
first_char = first_char + 1
last_char = last_char -1</i>
main()
Upvotes: 2
Views: 67
Reputation: 2242
You mean to do, in line 2:
s = s.lower()
There are more problems after that, but the specific problem you are having is that you are not calling the function (you need the parentheses).
Upvotes: 1
Reputation: 184405
The culprit is this line:
s = s.lower
Here you are assigning the method (or function) s.lower
to s
, overwriting the original string. At this point you have lost what the user typed in. You get the error because you can't use the []
notation with a function, which you try to do with e.g. s[first_char]
.
More than likely you intended to call the function and keep its return value, a lower-case value of the original string, in s
:
s = s.lower()
There are many other problems with your code but that is the one that's causing the error.
Upvotes: 1