“Python string palindrome” Kode Jawaban

Python - Cara Memeriksa Jika String Adalah Palindrome

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

Pemeriksaan Palindrome Menggunakan untuk Loop di 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

Bagaimana cara memeriksa apakah string yang diberikan adalah palindrome, dalam 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

Python string palindrome

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

Jawaban yang mirip dengan “Python string palindrome”

Pertanyaan yang mirip dengan “Python string palindrome”

Lebih banyak jawaban terkait untuk “Python string palindrome” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya