[英]In Python, how can I use a function's return statement within a second function without using global variables?
I'm working on an assignment in which the constraints specify that I cannot use global variables. 我正在做一个分配,其中约束指定我不能使用全局变量。 Variables are only defined for the specific function.
仅为特定功能定义变量。 I'm wondering if there is a way to take what a function returns (a string) and then create a new function that can use that string, without global variables?
我想知道是否有一种方法可以接受一个函数返回的内容(一个字符串),然后创建一个可以使用该字符串而无需全局变量的新函数? Note: I CAN use variables, just not globals.
注意:我可以使用变量,但不能使用全局变量。 Thanks!
谢谢!
Per request, here is an example. 根据请求,这是一个示例。
def func1():
return "output"
def func2():
#loop over the string "output",just for example
>>> def a():
... return 'x'
...
>>> def b(s):
... print 'b recieved', s
...
>>> b(a())
b recieved x
Why not pass the variable to the new function as a parameter? 为什么不将变量作为参数传递给新函数?
eg 例如
s = someFunc1()
someFunc2(s)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.