# Check if strings are rotations of each other or not in Python

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

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

Live Demo

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