Here, we are going to input string and determine whether it is palindrome or not ; we also convert the case of each characters of string in python. In python , We can easily change the case of characters of string using inbulit string function such as swapcase(). This function changes the uppercase letter to lowercase letter and lowercase letter to uppercase letter. In this python program, we ask user to enter any string (single word) and we reverse the position of characters .After that we check the reverse string is equal to original string or not
python program to check for palindrome string using for and if-else loop
# Python program to check
# if a string is palindrome
# or not
s = input("Enter any string :")
j = -1
flag = 0
for i in s:
if i != s[j]:
flag = 1
break
j = j - 1
if flag == 1:
print(s,"--> This string is not palindrome")
else:
print(s,"--> This string is palindrome")
sc = s.swapcase()
print("String after converting the case of each character :",sc)
Output
Enter any string :mam mam --> This string is palindrome String after converting the case of each character : MAM Enter any string :SuJata SuJata --> This string is not palindrome String after converting the case of each character : sUjATA