Last active
May 29, 2020 17:20
-
-
Save pratik7368patil/f99c7a492f87e6742789613b580997ab to your computer and use it in GitHub Desktop.
Check Palindrome String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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