Python之函数

it2025-01-13  5

1.定义函数 定义函数需要使用def,如下所示:

>>> def function(): ... """输入内容""" ... print('my name is function') ... >>> function() my name is function

2.函数传参

>>> def function(test_function): ... print("my name is "+test_function.title()+".") ... >>> function("quanquan") my name is Quanquan.

其中test_function为形参,quanquan为实参

>>> def function(test_function,admin_function): ... print("my name is "+test_function+"quan"+admin_function) ... >>> function("quan",".") my name is Quanquan.

3.返回值

>>> def function(test_function,admin_function): ... look_function="my name is "+test_function+"quan"+admin_function ... return look_function ... >>> value=function("quan",".") >>> print(value) my name is quanquan.
最新回复(0)