Answers for "rotate string in python"

0

rotate string in python

def rotate_string(s,d): 
  
    # slice string in two parts for left and right 
    Lfirst = s[0 : d] 
    Lsecond = s[d :] 
    Rfirst = s[0 : len(s)-d] 
    Rsecond = s[len(s)-d : ] 
  
    # now join two parts together 
    print ("Left Rotation : ", (Lsecond + Lfirst) )
    print ("Right Rotation : ", (Rsecond + Rfirst)) 
  
string = 'Studytonight'
d=4
rotate_string(string,d)
Posted by: Guest on August-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language