forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_int_palindrome.py
34 lines (28 loc) · 689 Bytes
/
is_int_palindrome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
defis_int_palindrome(num: int) ->bool:
"""
Returns whether `num` is a palindrome or not
(see for reference https://en.wikipedia.org/wiki/Palindromic_number).
>>> is_int_palindrome(-121)
False
>>> is_int_palindrome(0)
True
>>> is_int_palindrome(10)
False
>>> is_int_palindrome(11)
True
>>> is_int_palindrome(101)
True
>>> is_int_palindrome(120)
False
"""
ifnum<0:
returnFalse
num_copy: int=num
rev_num: int=0
whilenum>0:
rev_num=rev_num*10+ (num%10)
num//=10
returnnum_copy==rev_num
if__name__=="__main__":
importdoctest
doctest.testmod()