In this example we will show how to check if a string is a palindrome.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
str = input("Please input the string: ")
if str == str[::-1]:
print("This string is a palindrome.")
else:
print("This string is not a palindrome.")
Output:
Case 1:
Please input the string: hello world
This string is not a palindrome.
Case 2:
Please input the string: racecar
This string is a palindrome.