“Palindrome String Python” Réponses codées

Python - Comment vérifier si une chaîne est un palindrome

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

Vérification palindrome en utilisant la boucle en 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")
Curious Crane

Comment vérifier si une chaîne donnée est un palindrome, en 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
Wissam

Palindrome String Python

a=input('enter a string :')# palindrome in string
b=a[::-1]
if a==b:
    
 print(a,'is a palindrome')
else:
 print(a,'is not a palindrome')
 print('a is not equal to b')
 if a!=b:
   print(b, 'the reverse of', a)
#output:
--------------------------------------------------------------------------------
case-I
# not palindrome
enter a string :1254
1254 is not a palindrome
a is not equal to b
4521 the reverse of 1254
--------------------------------------------------------------------------------
case-II
# palindrme
enter a string :12321
12321 is a palindrome
Gr@Y_orphan_ViLL@in##

palindrome python

def palindrome(a):
    return a == a[::-1]

palindrome('radar') 		# True
VasteMonde

Programme Python Palindrome

n = input("Enter the word and see if it is palindrome: ") #check palindrome
if n == n[::-1]:
    print("This word is palindrome")
else:
    print("This word is not palindrome")
    print("franco")
Prickly Parrot

Réponses similaires à “Palindrome String Python”

Questions similaires à “Palindrome String Python”

Plus de réponses similaires à “Palindrome String Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code