如何基于python中的if条件调用函数[关闭]

问题描述 投票:-6回答:1

假设我在python中有2个函数。第二个函数func(b)仅在没有从func(a)获得期望的结果或func(a)中有错误时才应执行。基本上需要执行第二个函数仅在程序中有条件的情况下...对此有任何建议。.

def func(a):
  print (" Hello World")

def func(b)
  print ("calling this func as first func failed)

func(a)
func(b)
python
1个回答
0
投票
config = false def func(a): if(a == ?) { config = true; } print (" Hello World") def func2(b) print ("calling this func as first func failed) func(a) if(!config) { func2(b) }

您必须创建自己的条件,失败/成功的方式如何(f)(a)

要使用的功能,您不能使用相同的名称。

示例2:

def func(a): if(something == other) { return "failed" } return "?" def func2(b) print ("calling this func as first func failed) expect = func(a) if(expect != "?") { func2(b) }

或反转条件。

© www.soinside.com 2019 - 2024. All rights reserved.