
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to check strings are rotation of each other or not in Python
Suppose we have two English strings s and t, they can be in lowercase and/or uppercase. We have to check whether one is a rotation of the other or not.
So, if the input is like s = "koLKAta" t = "KAtakoL", then the output will be True
To solve this, we will follow these steps −
- if size of s is not same as size of t, then
- return False
- s := s concatenate s
- return True when t is present in s otherwise False
Example
Let us see the following implementation to get better understanding −
def solve(s, t): if len(s) != len(t): return False s = s + s return True if s.find(t) != -1 else False s = "koLKAta" t = "KAtakoL" print(solve(s, t))
Input
"koLKAta", "KAtakoL"
Output
True
- Related Articles
- Check if strings are rotations of each other or not in Python
- A Program to check if strings are rotations of each other or not?
- Write a program in JavaScript to check if two strings are anagrams of each other or not
- Check whether two strings are anagram of each other in Python
- Program to check whether final string can be formed using other two strings or not in Python
- Program to check two strings are 0 or 1 edit distance away or not in Python
- Program to check whether every rotation of a number is prime or not in Python
- C Program to check if two strings are same or not
- Program to check whether one tree is subtree of other or not in Python
- Java Program to check whether two Strings are an anagram or not.
- Check if bits in range L to R of two numbers are complement of each other or not in Python
- Check if two strings are anagram of each other using C++
- Program to check right rotation forms increasing or decreasing array with first n natural numbers or not in Python
- Check whether two strings are equivalent or not according to given condition in Python
- How to check if two Strings are anagrams of each other using C#?

Advertisements