Skip to main content
Practice

palindrome-check

---
id: palindrome-check
title: Checking for Palindrome Strings - Problem Solving
description: 3 Ways to Verify a Palindrome String
tags:
- Python
- Strings
- Palindrome
sidebar_position: 2
isPublic: false
---

# Checking for Palindrome Strings - Problem Solving

Check out 3 ways to determine if a string reads the same backwards.

<br />

```python title="Method 1"
def solution(s):
return s == s[::-1] # Reverse the string and compare it with the original to check for palindrome

When three values are provided for slicing using :, it represents [start:end:step].

start is the starting index, end is the ending index, and step indicates the increment.

start and end can be omitted, meaning the entire string from start to finish is considered.

[::-1] is a common Python expression to reverse a string. Here, :: means the entire string and -1 indicates that it should be read in reverse order.


Example Usage

Input/Output Example
result1 = solution("radar")
print(result1) # Output: True

result2 = solution("hello")
print(result2) # Output: False

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.