Python 程序检查一个字符串是否回文
给定一个字符串,我们的任务就是检查这个字符串是否回文。
算法
Step1: Enter string as an input. Step2: Using string slicing we reverse the string and compare it back to the original string. Step3: Then display the result.
示例代码
my_string=input("Enter string:") if(my_string==my_string[::-1]): print("The string is a palindrome") else: print("The string isn't a palindrome")
输出
Enter string:madam The string is a palindrome Enter string:python The string isn't a palindrome
广告