logo codesdope

How to store a string value when returned by a user defined function in python?

   Kartikey_Chauhan

import re
def palindrome(st1,st2,i):
    if(i<0):
        print(st2)
        return st2       
    else:
        st2=st2+st1[i]
        i=i-1
        palindrome(st1,st2,i)
def main():
    st0=input("enter the string")
    st=""
    le=len(st0)-1
    stk=palindrome(st0,st,le)
    print(stk)

    if(bool(re.match(st0,stk))):
        print("string is palindrome")
    else:
        print("string is not palindrome")
main()       

 

 

 

I am running the above code and from function “palindrome” a string value is returned  and stored in variable “stk” in side main.

But when I print ‘stk’ then the value printed is none .

Where am Iwrong ? Please tell me.


Answers

Download Our App.
BlogsDope App
Get it on Google Play
Write your answer
Close

Welcome.please sign up.

Close

Welcome.please login.