Most efficient palindrome program for python -
this question has answer here:
- how check palindrome using python logic 27 answers
very new programming , trying solve few project euler problems. know python code identifies palindrome , non-palindrome. efficient way this? please show code find efficient problem.
you can checking if string input equal reversed (that's palindrome is).
def check_palindrome(s): return s == s[::-1]
[::-1]
reverses string because -1
tells how many steps go , negative go through string in reverse.
if need check if integers palindromes, can do:
def check_palindrome(s): return str(s) == str(s)[::-1]
Comments
Post a Comment