Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Palindrome Check using for loop in python

p = list(input())
for i in range(len(p)):
    if p[i] == p[len(p)-1-i]:
        continue
    else:
         print("NOT PALINDROME")
         break
else:
    print("PALINDROME")
Comment

How to check for palindromes in python

def is_palindrome(s):
  reverse = s[::-1]
  if (s == reverse):
    return True
  return False

s1 = 'racecar'
s2 = 'hippopotamus'

print(''racecar' a palindrome -> {}'.format(is_palindrome(s1)))
print(''hippopotamus' a palindrome -> {}'.format(is_palindrome(s2)))


# output

# 'racecar' is a palindrome -> True
# 'hippopotamus' is a palindrome -> False
Comment

Python - How To Check if a String Is a Palindrome

word = input() if str(word) == str(word)[::-1] :     print("Palindrome") else:     print("Not Palindrome")
Comment

Python Program to Check if binary representation is a palindrome

# Function to check if binary representation of
# a number is palindrome or not
 
def binarypalindrome(num):
 
     # convert number into binary
     binary = bin(num)
 
     # skip first two characters of string
     # because bin function appends '0b' as
     # prefix in binary representation of
     # a number
     binary = binary[2:]
 
     # now reverse binary string and compare
     # it with original
     return binary == binary[-1::-1]
 
# Driver program
if __name__ == "__main__":
    num = 9
    print binarypalindrome(num)
Comment

How to check if a given string is a palindrome, in Python?

"""
This implementation checks whether a given
string is a palindrome. A string is 
considered to be a palindrome if it reads the
same forward and backward. For example, "kayak"
is a palindrome, while, "door" is not. 

Let n be the length of the string

Time complexity: O(n), 
Space complexity: O(1)
"""
def isPalindrome(string):
    # Maintain left and right pointers
    leftIdx = 0
    rightIdx = len(string)-1
    while leftIdx < rightIdx:
        # If chars on either end don't match
        # string cannot be a palindrome
        if string[leftIdx] != string[rightIdx]:
            return False
        # Otherwise, proceed to next chars
        leftIdx += 1
        rightIdx -= 1
    return True

print(isPalindrome("kayak"))  # True
print(isPalindrome("door"))  # False
Comment

how to check a string is palindrome or not in python

s = "001100"

if s == s[::-1]:
    print(s, "is a Palindrome string.")
else:
    print("Not a palindrome string.")

    
Comment

How to check palindrom in python

myString = "aba"
if myString == myString[::-1]:
	print("The string '" + myString + "' is a palindrome")
else:
	print("The string '" + myString + "' is not a palindrome")
Comment

check palindrome in python

string = input("Type a string: ")
if string[::-1] == string: 
	print(string,"This string is Palindrome")
else:
	print(string,"This string is not Palindrome")
Comment

finding palindrome in python

is_palindrome = lambda phrase: phrase == phrase[::-1]

print(is_palindrome('anna')) # True 
print(is_palindrome('rats live on no evil star')) # True 
print(is_palindrome('kdljfasjf')) # False 
Comment

PREVIOUS NEXT
Code Example
Python :: bar plot bokeh 
Python :: How to send Email verification codes to user in Firebase using Python 
Python :: python exception 
Python :: torch flatten 
Python :: at=error code=H10 desc="App crashed" django 
Python :: how append a directory based on current directory python 
Python :: python pandas table save 
Python :: map example in python 
Python :: python index of string 
Python :: how to get user id django 
Python :: python list pop vs remove 
Python :: short if python 
Python :: print random integers py 
Python :: python dictionary append value if key exists 
Python :: import all csv as append dataframes python 
Python :: python autocorrelation plot 
Python :: load pt file 
Python :: how to enter a int in python 
Python :: numpy copy array 
Python :: python game 
Python :: Display the data types of the DataFrame 
Python :: django request user 
Python :: python hash() seed 
Python :: python int16 
Python :: python namespace 
Python :: Week of the year Pandas 
Python :: python max function with lambda 
Python :: get random number positive or negative python 
Python :: python to run excel macro 
Python :: get basename without extension python 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =