养生 装修 购物 美食 感冒 便秘 营销 加盟 小吃 火锅 管理 创业 搭配 减肥 培训 旅游

如何在PYTHON里运用return

时间:2024-10-22 12:24:58

在PYTHON里运用return

工具/原料

PYTHON

方法/步骤

1、打开JUPYTERNOTEBOOK,新建一个PY文档。

如何在PYTHON里运用return

2、print("ok")初学者都知道print可以打印相应的数据。其实有另外一个类似的函数。

如何在PYTHON里运用return

3、return"ok"return其实类似于print,但是一定要在函数里面用。

如何在PYTHON里运用return

4、print("okA&孥恶膈茯quot;)deffunc():return"okB"print(f锇栀劐箨unc())print("okC")设置在function里面就可以用return了。

如何在PYTHON里运用return

5、print("okA&孥恶膈茯quot;)deffunc1():return("okB")print烫喇霰嘴(func1())print("okC")实际上可以类似于print加上括号。

如何在PYTHON里运用return

6、print("okA")deffunc2():returnprint(func2())print("okC")如果return后面什么都没有,其实是不会输出的。

如何在PYTHON里运用return

7、print("okA&孥恶膈茯quot;)deffunc3():returnTrueprint("okA媪青怍牙")print(func3())print("okC")如果设置了返回值,返回值后面的就不显示了。

如何在PYTHON里运用return

8、print("okA")deffunc4():return3,4print(func4())print("okC")可以同时设置多个返回值。

如何在PYTHON里运用return

9、print("okA")deffunc5():return3+4print(func5())print("okC")我们也可以让返回值进行运算。

如何在PYTHON里运用return

© 一点知识