“Palindrome String Python” Kod odpowiedzi

Python - jak sprawdzić, czy sznur jest palindromem

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

Kontrola palindromu za pomocą pętli w Pythonie

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

Jak sprawdzić, czy dany ciąg jest palindromem, w Pythonie?

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

Program 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

Odpowiedzi podobne do “Palindrome String Python”

Pytania podobne do “Palindrome String Python”

Więcej pokrewnych odpowiedzi na “Palindrome String Python” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu