On 05/31/2015 09:46 PM, fl wrote:
Hi,
When I search solution of reverse a string/number, I came across a short
function online:
def palindrome(num):
return str(num) == str(num)[::-1]
I thought that it is a general function. And with the following variable:
No, this function is not built into Python because ... Well it's hard
to say why. It's not very general, or not useful to many programmers,
or nobody's thought about it or made a case for including it in Python, etc.
But that should be no problem. You can define it yourself (by entering
the two line you have above). Then it will be defined, and calling
parlindrome('...')
will produce a result rather than an error.
Gary Herron
a
'1234_5555'
parlindrome(a)
Traceback (most recent call last):
File "<pyshell#126>", line 1, in <module>
parlindrome(a)
NameError: name 'parlindrome' is not defined
Then, I find that parlindrome is a special checking mirrored word.
I use Python 2.7.9. Why does the error message show
name 'parlindrome' is not defined
Thanks,
--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418
--
https://mail.python.org/mailman/listinfo/python-list