Python 3 palindrome checker
1

I personally like to reduce the amount of string assembling where possible, so instead of:

result = 'PASS' if is_pal else 'FAIL'
str_not = 'a' if is_pal else 'not a'
print('{}: {} is {} palindrome'.format(result, repr(arg), str_not))


I would write:

PASS_TMPL = "PASS: {!r} is a palindrome"
FAIL_TMPL = "FAIL: {!r} is not a palindrome"
s = (PASS_TMPL if is_pal else FAIL_TMPL).format(arg)


In your example you had 3 variables in the string, in my example it's reduced to just 1 variable and 2 different templates.

of-course in this small program probably it doesn't matter which style you use. However if you build larger application the later style will bring you a few benefits:


output is more easily predictable
easier to change the output string without having a need to refactor the code
when debugging, and having to find location in code which produced certain output, it will be easier to grep the code for the specific string in question, if there is less string assembling going on.
if you need to add i18n support for your application at some point in time, you will learn that the way you assembled the strings only works in english, and your code needs to be refactored in order to support other languages


Because both styles usually are equally easy to code, avoiding the first style and preferring the 2nd style I think is a good habit to pick up.

2

Instead of the for loop to compare every individual letter, you can compare if the word is equal reversed version of it:

return word == word[::-1]



word[::-1] will reverse the word


This is not only shorter to write, but also in interpreted languages like python should run much faster too. A simple loop in python is very slow compared to a simple loop in C. String comparison will use compiled C implementation instead of looping each letter in python's loop.