在PYTHON里运用return
工具/原料
PYTHON
方法/步骤
1、打开JUPYTERNOTEBOOK,新建一个PY文档。
2、print("ok")初学者都知道print可以打印相应的数据。其实有另外一个类似的函数。
3、return"ok"return其实类似于print,但是一定要在函数里面用。
4、print("okA&孥恶膈茯quot;)deffunc():return"okB"print(f锇栀劐箨unc())print("okC")设置在function里面就可以用return了。
5、print("okA&孥恶膈茯quot;)deffunc1():return("okB")print烫喇霰嘴(func1())print("okC")实际上可以类似于print加上括号。
6、print("okA")deffunc2():returnprint(func2())print("okC")如果return后面什么都没有,其实是不会输出的。
7、print("okA&孥恶膈茯quot;)deffunc3():returnTrueprint("okA媪青怍牙")print(func3())print("okC")如果设置了返回值,返回值后面的就不显示了。
8、print("okA")deffunc4():return3,4print(func4())print("okC")可以同时设置多个返回值。
9、print("okA")deffunc5():return3+4print(func5())print("okC")我们也可以让返回值进行运算。