python函数已调用但未返回值.应该很简单 [英] python function called but not returning value. Should be simple

查看:220
本文介绍了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

这篇关于python函数已调用但未返回值.应该很简单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆