MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_palindrome

Function is_palindrome

project_euler/problem_125/sol1.py:19–32  ·  view source on GitHub ↗

Check if an integer is palindromic. >>> is_palindrome(12521) True >>> is_palindrome(12522) False >>> is_palindrome(12210) False

(n: int)

Source from the content-addressed store, hash-verified

17
18
19def is_palindrome(n: int) -> bool:
20 """
21 Check if an integer is palindromic.
22 >>> is_palindrome(12521)
23 True
24 >>> is_palindrome(12522)
25 False
26 >>> is_palindrome(12210)
27 False
28 """
29 if n % 10 == 0:
30 return False
31 s = str(n)
32 return s == s[::-1]
33
34
35def solution() -> int:

Callers 1

solutionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected