Python 我无法打印函数外部的fi值

Python 我无法打印函数外部的fi值,python,function,printing,return,Python,Function,Printing,Return,返回fi 或 使fi成为可以从任何地方访问的全局变量 s= input("enter the string to be checked") def pig(s): first=s[0] if first in "aeoui": fi=s + "ay" else: fi=s[1:]+first+"ay" return fi fi = pig(s) print(fi) 您应该了解什么是全局变量isglobal可以说是最糟糕的解决方案之一,特别是对于初学者,我

返回fi

或 使fi成为可以从任何地方访问的全局变量

s= input("enter the string to be checked") 
def pig(s): 
    first=s[0] 
    if first in "aeoui": fi=s + "ay" 
    else: fi=s[1:]+first+"ay"
    return fi
fi = pig(s)
print(fi)

您应该了解什么是全局变量isglobal可以说是最糟糕的解决方案之一,特别是对于初学者,我建议在返回不合适时使用简单的OOP原则
s= input("enter the string to be checked") 
def pig(s): 
    first=s[0] 
    if first in "aeoui": fi=s + "ay" 
    else: fi=s[1:]+first+"ay"
    return fi
fi = pig(s)
print(fi)
s= input("enter the string to be checked") 
def pig(s): 
    global fi
    first=s[0] 
    if first in "aeoui": fi=s + "ay" 
    else: fi=s[1:]+first+"ay"
pig(s)
print(fi)