Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在处理一个约束指定我不能使用全局变量的赋值。变量仅针对特定功能定义。我想知道是否有一种方法可以获取函数返回的内容(字符串),然后创建一个可以使用该字符串的新函数,而无需全局变量?注意:我可以使用变量,但不能使用全局变量。谢谢!
根据请求,这是一个示例。
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
为什么不将变量作为参数传递给新函数?
例如
s = someFunc1() someFunc2(s)