This is a Python Program to check whether a given number is a palindrome. Problem Description The program takes a number and checks whether it is a palindrome or not. Problem Solution 1. Take the value of the integer and store in a variable. Program/Source Code Here is source code of the Python Program to check whether a given number is a palindrome. The program output is also shown below. Program Explanation 1. User must first enter the value of the integer and store it in a
variable. Runtime Test Cases Case 1 Enter number:121 The number is a palindrome! Case 2 Enter number:567 The number isn't a palindrome! Sanfoundry Global Education & Learning Series – Python Programs. To practice all Python programs, here is complete set of 150+ Python Problems and Solutions. Next Steps:
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn. Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses. View Discussion Improve Article Save Article View Discussion Improve Article Save Article Sometimes, we have an application of checking a number is palindrome or not and it’s quite common while day-day programming or competitive programming, it’s easy to reverse a number and check it but sometimes for readability and reducing lines of code, we require to perform this in one-liner logic. Let’s discuss certain ways in which this can be achieved.
Method #1 : Using
Output: The original number is : 9669669 Is the number palindrome ? : True
Output: The original number is : 9669669 Is the number palindrome ? : True We can also read input as string and then simply check for palindrome.
What is a palindromic integer?A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed. Negative numbers are not palindromic. Example : Input : 12121 Output : 1. Input : 123 Output : 0.
What is palindrome number example?A palindrome number is a number that remains the same when digits are reversed. For example, the number 12321 is a palindrome number, but 1451 is not a palindrome number.
Is there palindrome function in Python?3. Using Built-in Functions. We can also check palindrome in Python with the help of the built-in reversed() function provided for sequence data types in Python: reversed(sequence) : It returns an iterator that accesses the sequence passed as an argument in the reverse order.
How do you print a palindrome in Python?Palindrome Program. str = 'JaVaJ'. strstr = str.casefold(). # This string is reverse.. rev = reversed(str). if list(str) == list(rev):. print("PALINDROME !"). print("NOT PALINDROME !"). |