๐งช Programming
โฑ๏ธ 80s
๐ 730 chars
๐ฆ 7.2B
๐ง Q4_K_M
Prompt: Write a Python function is_palindrome(s) that returns True if s is a palindrome. One test case.
Response
Sure, here's a simple Python function for checking if a string is a
palindrome. A palindrome is a word or phrase that reads the same backward a
as forward.
```python
def is_palindrome(s):
s = s.lower() # convert to lowercase for case-insensitive palindrome c
check
reversed_s = s[::-1] # reverse the string
if s == reversed_s:
return True
else:
return False
# Test case
print(is_palindrome("racecar")) # Should print: True
```
In this code, `[::-1]` is used to reverse the string in Python. The
function then compares the original string with its reversed version and re
returns `True` if they are equal (i.e., the string is a palindrome).