Write a Python function that checks whether a passed string is palindrome or not


Introduction

Write a Python function that checks whether a passed string is palindrome or not. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. def isPalindrome(string):
  2. left_pos = 0
  3. right_pos = len(string) - 1
  4.  
  5. while right_pos >= left_pos:
  6. if not string[left_pos] == string[right_pos]:
  7. return False
  8. left_pos += 1
  9. right_pos -= 1
  10. return True
  11. print(isPalindrome('12121'))

Result

python language techstudy.org

     





Related Topics




Popular Posts