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

Function is_palindrome

project_euler/problem_036/sol1.py:21–36  ·  view source on GitHub ↗

Return true if the input n is a palindrome. Otherwise return false. n can be an integer or a string. >>> is_palindrome(909) True >>> is_palindrome(908) False >>> is_palindrome('10101') True >>> is_palindrome('10111') False

(n: int | str)

Source from the content-addressed store, hash-verified

19
20
21def is_palindrome(n: int | str) -> bool:
22 """
23 Return true if the input n is a palindrome.
24 Otherwise return false. n can be an integer or a string.
25
26 >>> is_palindrome(909)
27 True
28 >>> is_palindrome(908)
29 False
30 >>> is_palindrome('10101')
31 True
32 >>> is_palindrome('10111')
33 False
34 """
35 n = str(n)
36 return n == n[::-1]
37
38
39def solution(n: int = 1000000):

Callers 1

solutionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected