Python 子函数中怎么使用if
1、这里以sublime text3作为示范,先创建一个py文档。


2、def func1():
pass
def func2():
pass
这里创建两个函数,因为我们要设定子函数。

3、def func2():
return "Apple!"
print(func2())
比如我们要把这个设定为子函数,先设定内容。

4、def func1():
if func2() == "Apple!":
return "This is an apple!"
else:
return "Null"
然后我们设定父函数,这里加入if判断,并且要把子函数加入。

5、print(func1())
我们运行一下父函数,就能看到由于if判断得出的结果。

6、def func1():
return func2("Apple")
def func2(x):
if x:
return True
else:
return Flase
print(func1())
如果要在子函数里面用if,让主函数用到,那么我们要在子函数里面设定参数。

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:154
阅读量:107
阅读量:39
阅读量:94
阅读量:114