[英]In Python, how can I use a function's return statement within a second function without using global variables?
我正在做一個分配,其中約束指定我不能使用全局變量。 僅為特定功能定義變量。 我想知道是否有一種方法可以接受一個函數返回的內容(一個字符串),然后創建一個可以使用該字符串而無需全局變量的新函數? 注意:我可以使用變量,但不能使用全局變量。 謝謝!
根據請求,這是一個示例。
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.