“Palindrome String Python” Code-Antworten

Python - So überprüfen Sie, ob eine Schnur ein Palindrom ist

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

Palindrome check verwendet, um für Schleife in Python zu sein

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

Wie kann ich prüfen, ob eine bestimmte Saite in Python ein Palindrom ist?

"""
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##

Python Palindrome

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

palindrome('radar') 		# True
VasteMonde

Python Palindrome -Programm

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

Ähnliche Antworten wie “Palindrome String Python”

Fragen ähnlich wie “Palindrome String Python”

Weitere verwandte Antworten zu “Palindrome String Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen