Check Whether the String is Symmetrical or Palindrome - Python Last Updated : 27 Oct, 2025 Comments Improve Suggest changes 76 Likes Like Report Given a string, the task is to check whether it is symmetrical or a palindrome.A string is symmetrical if the first half matches the second half (ignoring the middle character for odd-length strings).A string is a palindrome if it reads the same forwards and backwards.For example:s = "amaama" -> symmetrical (ama matches ama) and palindrome.s = "abcba" -> palindrome but not symmetrical (ab ≠ ba).Let’s explore efficient methods to check symmetry and palindrome properties.Using String Slicing This method uses Python’s slicing feature to directly compare parts of the string. It is the fastest and simplest way to check for symmetry and palindrome properties. Python s = "abaaba" half = len(s) // 2 sym = s[:half] == s[half:] if len(s) % 2 == 0 else s[:half] == s[half+1:] pal = s == s[::-1] print("Symmetrical" if sym else "Not Symmetrical") print("Palindrome" if pal else "Not Palindrome") OutputSymmetrical Palindrome Explanation:s[:half] slices the first half of the string.s[half:] or s[half+1:] slices the second half depending on even/odd length.s[::-1] reverses the string for the palindrome check.Comparisons return True/False and determine the output.Using Two Pointer TechniqueThis method uses two pointers from both ends of the string to check palindrome, and a loop to check symmetry by comparing halves. It is memory-efficient and avoids creating extra strings. Python s = "amaama" pal = True i, j = 0, len(s) - 1 while i < j: if s[i] != s[j]: pal = False break i += 1 j -= 1 half = len(s) // 2 sym = True for i in range(half): if len(s) % 2 == 0: if s[i] != s[i + half]: sym = False break else: if s[i] != s[i + half + 1]: sym = False break print("Symmetrical" if sym else "Not Symmetrical") print("Palindrome" if pal else "Not Palindrome") OutputSymmetrical Palindrome Explanation:Palindrome: while loop compares characters from left (i) and right (j). Breaks on mismatch.Symmetry: for loop compares characters of the first half with the second half, skipping the middle character for odd-length strings.Using all() with Generator ExpressionThis method uses a generator inside all() to check palindrome. Symmetry is checked by slicing. Efficient because it stops at first mismatch and uses constant extra memory. Python s = "amaama" half = len(s) // 2 # Palindrome pal = all(s[i] == s[-i-1] for i in range(len(s)//2)) # Symmetry sym = s[:half] == s[half:] if len(s) % 2 == 0 else s[:half] == s[half+1:] print("Symmetrical" if sym else "Not Symmetrical") print("Palindrome" if pal else "Not Palindrome") OutputSymmetrical Palindrome Explanation:range(len(s)//2) generates indices for the first half.s[-i-1] accesses the corresponding character from the end.all() returns False at the first mismatch, avoiding unnecessary comparisons. Create Quiz Comment V vanshikagoyal43 Follow 76 Improve V vanshikagoyal43 Follow 76 Improve Article Tags : Python Python Programs Python string-programs python Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like