python函数已调用但未返回值.应该很简单

python函数已调用但未返回值.应该很简单

问题描述:

我有一个功能:

def user_login(m):
    m = "user_login function called"
    return m

致电:

user_login(message)

它应该更改一个字符串m并返回结果.我知道该函数被调用是因为它抛出了一个错误[user_login()正好有1个参数(给定0)],如果我没有在其中输入参数的话.但是它不返回字符串.我如何找出问题所在?

It should change a string, m, and return the result. I know that the function gets called because it throws up an error [user_login() takes exactly 1 argument (0 given)] if I don't put an argument in it. But it doesn't return a string. How can I find out what's wrong?

您不能更改字符串"-相反,您应该做的是将函数的结果分配给调用范围内的字符串:

You can't "change the string" - instead, what you should be doing, is assigning the result of the function to your string in the calling scope:

m = user_login('some message')
print m