Check if String formed by first and last X characters of a String is a Palindrome | Function to check whether the first x characters of both string str and reversed string str are same or not ; Length of the string str ; Traverse over the string while first and last x characters are not equal ; If the current and n - k - 1 from last character are not equal ; Finally , print true ; Driver Code ; Given input ; Function Call
def isEqualSubstring ( string , x ) : NEW_LINE INDENT n = len ( string ) NEW_LINE i = 0 NEW_LINE while i < n and i < x : NEW_LINE INDENT if ( string [ i ] != string [ n - i - 1 ] ) : NEW_LINE INDENT print ( " false " ) NEW_LINE return NEW_LINE DEDENT i += 1 NEW_LINE DEDENT print ( " true " ) NEW_LINE return NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT string = " GeeksforGeeks " NEW_LINE x = 3 NEW_LINE isEqualSubstring ( string , x ) NEW_LINE DEDENT