当前位置:网站首页>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 ).
边栏推荐
猜你喜欢

ContentProvider of four components

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte

Map and set

Use of jvisualvm

Intent (whether there is return value to jump)

Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.

Togglebutton (button switch)

JS 事件监听 鼠标 键盘 表单 页面 onclick onkeydown onChange

Sqlife (database)

化工巨头巴斯夫&Pasqal:利用量子神经网络优化天气预报
随机推荐
SharePreference(存储)
11.2DHCP
C191:密码编译
View pagoda PHP extension directory
疫情下我离职一年,收入增长了10倍
PC博物馆(3) MITS Altair 8800
Static test. 2021.01 .13
Intel launched the world's smallest high-resolution lidar, priced at only $349
SumMenuDemo(子菜单)
真实案例,大学生接单被骗,希望大家不要被骗了【惨痛教训】
11.5.OSPF
Pytorch reports CUDA error: no kernel image is available for execution on the device error
文件操作防护
Gesturedetector (gesture recognition)
Influxdb series (IV) TSM engine (storage principle)
TSMC 5nm is about to mass produce: Apple A14 monopolizes 70% of the production capacity, and Huawei Kirin 1020 takes 30%
链表~~~
函数总结
AutoCompleteTextView (input box pre match)
The first Xiaolong 765G! Redmi K30 5g release: support 5g dual-mode 120Hz screen, priced from 1999 yuan