
- 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
Check if strings are rotations of each other or not in Python
Suppose we have two strings s and t, we have to check whether t is a rotation of s or not.
So, if the input is like s = "hello", t = "llohe", 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
- temp := s concatenate with s again
- if count of t in temp > 0, then
- return True
- return False
Let us see the following implementation to get better understanding −
Example Code
def solve(s, t): if len(s) != len(t): return False temp = s + s if temp.count(t)> 0: return True return False s = "hello" t = "llohe" print(solve(s, t))
Input
"hello", "llohe"
Output
True
- Related Articles
- A Program to check if strings are rotations of each other or not?
- Program to check strings are rotation of each other or not in Python
- Check if all rows of a matrix are circular rotations of each other in Python
- 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
- Check if two strings are anagram of each other using C++
- Check if two strings are equal or not in Arduino
- Check if bits in range L to R of two numbers are complement of each other or not in Python
- Check if concatenation of two strings is balanced or not in Python
- How to check if two Strings are anagrams of each other using C#?
- C Program to check if two strings are same or not
- 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
- Check whether two strings are equivalent or not according to given condition in Python
- Check if all elements of the array are palindrome or not in Python

Advertisements