我是Python的新手,想知道Python(或IPython)是否与R中的invisible()函数等效。invisible()函数返回值,但如果以交互方式运行,则不显示它们,而是仅使它们可用进行分配。例如:
doStuff <- function(x) {
// blah blah
return(invisible(retValue))
}
z = doStuff(x) // z has the return value
doStuff(x) // retValue doesn't get displayed
Run Code Online (Sandbox Code Playgroud)
小智 2
There does not seem to be a proper function in Python that is the same as R's invisible() function. However, you can simply use a variable set to a boolean value and then use an if statement to check if the boolean is set to True then you return the output of the function. Below is a simple version of what the code could look like, you can make this more complex and improve it (if this does not help you then I suggest that you put some research into function outputs in python):
def function(INPUTS):
# function code to get ouput
return_value = False
if return_value == True:
return ouputRun Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
692 次 |
| 最近记录: |