当前位置:网站首页>Function knowledge points
Function knowledge points
2022-07-06 02:43:00 【wwanxinghao】
Function definition : Encapsulate a specific function or code , When you need to use this function, you can call it directly
Parameters : When a function is called , Pass some information to the function
Parameter classification :
One . Shape parameter , At the time of function definition , You need to prepare some variables to receive information
1. Positional arguments , Declare variables one by one according to position
2. Default parameter , Give a default value when the function is declared , If the argument is not passed , The default value takes effect
3. Dynamic transfer parameters
1.*args, Indicates the dynamic transfer of all position parameters
2.**kwargs, It means to take over the dynamic parameters of all keywords
The order : Location >*args> The default value is >**kwargs
Two 、 Actual parameters : The information actually transmitted during electrophoresis
1. Positional arguments , Pass parameters by position
2. Key parameters , Pass parameters according to the name of the parameter
3. Mixing parameters :
The order : Put the position parameter in front , Key parameters after → Otherwise, the report will be wrong , The official setting is like this
Return value : After function execution , Will give the caller a result , The result is the return value
About return:
1. As long as the function executes return, The function immediately stops and returns the contents , Within the function return The subsequent code of will not be executed
2. If the function does not return, At this time, the outside world takes over None
3. If it's written return
1. Only written. retuan, Data is not followed , At this time, it is still None → amount to break
2.return value , At this time, the function has a return value , The outside world can take over a data → Most used
3.return value 1, value 2, value 3....., At this time, the function has multiple return values , The outside world receives tuples
Knowledge points to master function :
1. Nested function
2. Scope of variable
3. Closure
4. Decorator
# fn: A function ;inner,ret Just change the name
def wrapper(fn):
def inner(*args,**kwargs):
ret = fn(*args,**kwargs)
return ret
return inner()
@wrapper
def func():
pass
5. iterator
6. generator
“ We can only go forward ”
yield
g = (x for x in xx)
7. The derived type
8. Anonymous functions
9.python Built in functions
边栏推荐
- Solution: attributeerror: 'STR' object has no attribute 'decode‘
- 力扣今日題-729. 我的日程安排錶 I
- Data preparation
- Redis skip table
- MySQL winter vacation self-study 2022 11 (6)
- There are so many giants, why should we independently develop POS store cashier system?
- Introduction to robotframework (II) app startup of appui automation
- Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
- Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
- CobaltStrike-4.4-K8修改版安装使用教程
猜你喜欢
Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)
PMP practice once a day | don't get lost in the exam -7.5
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
Initial understanding of pointer variables
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)
A copy can also produce flowers
How to accurately identify master data?
随机推荐
2020.02.11
2345文件粉碎,文件强力删除工具无捆绑纯净提取版
How to read excel, PDF and JSON files in R language?
Pat 1046 shortest distance (20 points) simulation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
QT release exe software and modify exe application icon
继承的构造函数
Y a - t - il des cas où sqlcdc surveille plusieurs tables et les associe à une autre? Tout fonctionne dans MySQL
Six stone management: why should leaders ignore product quality
UE4 - how to make a simple TPS role (I) - create a basic role
Differences and usage scenarios between TCP and UDP
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Redis cluster deployment based on redis5
Li Kou today's question -729 My schedule I
Master data management theory and Practice
A doctor's 22 years in Huawei
2.13 simulation summary
【若依(ruoyi)】启用迷你导航栏
MySQL winter vacation self-study 2022 11 (8)
Introduction to robotframework (III) Baidu search of webui automation