Skip to content

Instantly share code, notes, and snippets.

@pratik7368patil
Last active May 29, 2020 17:20
Show Gist options
  • Save pratik7368patil/f99c7a492f87e6742789613b580997ab to your computer and use it in GitHub Desktop.
Save pratik7368patil/f99c7a492f87e6742789613b580997ab to your computer and use it in GitHub Desktop.
Check Palindrome String
# if you know what is palindrome means and how to reverse a string
# then you know answer
# 1. Method using string slicing
def check_palindrome(string):
# you can not compair case sensitive strings
string = string.lower()
if string == string[::-1]:
return True
else:
return False
string = "codeedoc" # input string
print(check_palindrome(string))
# the output will be True
########################################
# 2. Method using reverse()
def check_palindrome(string):
# you can not compair case sensitive strings
string = string.lower()
if string == string.reverse():
return True
else:
return False
string = "codeedoc" # input string
print(check_palindrome(string))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment