当前位置:网站首页>Function summary
Function summary
2022-07-27 19:56:00 【Hug Mo Mo】
One , Definition
A function is a collection of function codes with names 》.
A piece of code or instruction used to explain a problem , Collection with name .## Two , Why use functions :
Reduce code duplication .## 3、 ... and , Use of functions :
1, The body of the function ,
2, Function gets a result , If the caller needs to return this def The name of the function ([ parameter list ])
Example :def show(ls):
print()
Call of function :
The name of the function (【 Actual parameters 】)
Example :def insert (list)
insert(ls) ## Four , Classification of functions :
1, With or without parameters
2, Is there a return value
Example :def add(x,y)
return x+y
call :
res=add(4,8)
print(" And is “,yes)
5、 ... and , Global function :
To force modification of global functions , Use global Variable name declaration of .
python Of main function : if name == ‘main’:
python It's a scripting language , So it's main Functions and c perhaps java Wait for something different
python Medium main Functions are not where the code starts , Written in main The code in the function is generally the test code , Used to test the current module
It cannot be imported into other modules. The default value parameters : When the function is defined , If the values of some parameters , Generally, it is not invariable to a certain value , You can set this parameter as the default parameter , In this way, the trouble of the caller is reduced. The function is passed to the function as a parameter :
python in , A function is essentially an object ,python in , The argument type of the function is python All types in
Conclusion
: stay python, Functions can be passed as arguments inside functions lambda expression :
Be careful : If you need to return a value , No need to add return, It will automatically come back lambda [ parameter list ]: The body of the function
*
lambda effect : advantage :
1、 stay python Implement anonymous functions
2、 Simplified programming shortcoming :
shortcoming
Reduced the readability of the code , Increase the complexity of the code , It improves the partial function of code maintenance cost :
Partial function definition : Modify or increase the default value of a function parameter , It is called partial function ## arge Variable function
The problem of passing a function as a parameter to the inside of a function :
fn( )
The function itself can be used as an argument ( Characteristics of weak data types ).## One , Definition
A function is a collection of function codes with names 》.
A piece of code or instruction used to explain a problem , Collection with name .
Two , Why use functions
:
Reduce code duplication .
3、 ... and , Use of functions :
1, The body of the function ,
2, Function gets a result , If the caller needs to return this
def The name of the function ([ parameter list ])
Example :def show(ls):
print()
Call of function :
The name of the function (【 Actual parameters 】)
Example :def insert (list)
insert(ls)
Four , Classification of functions
:
1, With or without parameters
2, Is there a return value
Example :def add(x,y)
return x+y
call :
res=add(4,8)
print(" And is “,yes)
5、 ... and , Global function :
To force modification of global functions , Use global Variable name declaration of .
python Of main function :
f name == ‘main’:
# python It's a scripting language , So it's main Functions and c perhaps java Wait for something different
# python Medium main Functions are not where the code starts , Written in main The code in the function is generally the test code , Used to test the current module
# It cannot be imported into other modules. The default value parameters : When the function is defined , If the values of some parameters , Generally, it is not invariable to a certain value , You can set this parameter as the default parameter , This reduces the trouble of the caller
The problem of passing a function as a parameter to the inside of a function :
python in , A function is essentially an object ,python in , The argument type of the function is python All types in
Conclusion : stay python, Functions can be passed as arguments inside functions lambda expression :
# Be careful : If you need to return a value , No need to add return, It will automatically come back lambda [ parameter list ]: The body of the function
lambda effect :
advantage :
1、 stay python Implement anonymous functions
2、 Simplified programming shortcoming :
shortcoming
Reduced the readability of the code , Increase the complexity of the code , It improves the partial function of code maintenance cost :
Partial function definition : Modify or increase the default value of a function parameter , It is called partial function
arge Variable function
The problem of passing a function as a parameter to the inside of a function :
fn( )
The function itself can be used as an argument ( Characteristics of weak data types ).
边栏推荐
- Flink introduction and operation architecture
- [basic knowledge of deep learning - 39] comparison of BN, LN and WN
- Datepicker and TimePicker
- pytorch lstm+attention
- DatePicker(日期选择器)与TimePicker(时间选择器)
- AutoCompleteTextView(输入框预匹配)
- IDEA:解决代码没有提示问题
- 访问控制
- Detailed explanation of the underlying data structure of redis
- 化工巨头巴斯夫&Pasqal:利用量子神经网络优化天气预报
猜你喜欢
随机推荐
[basic knowledge of deep learning - 42] detailed explanation of logistic regression
BroadcastReceiver(广播)
文件操作防护
Remember an unprepared internship interview
Session攻击
VS2017#include 'xxx.h'
11.5.OSPF
pytorch lstm+attention
内置模块10.18
Broadcastreceiver (broadcast)
2022爱分析·智慧社区厂商全景报告 厂商征集
In a real case, college students were cheated when taking orders. I hope you won't be cheated [painful lesson]
Combinatorics -- permutation and combination
View pagoda PHP extension directory
Ericsson admitted bribery in China and other five countries and paid a fine of $1.06 billion to the United States
NAT 11.16
Application pool has been disabled
Online Judge 输出超限
[basic knowledge of in-depth learning - 40] Why does CNN have more advantages than DNN in the field of images
中国业务型CDP白皮书 | 爱分析报告







