当前位置:网站首页>Precautions for function default parameters (formal parameter angle)
Precautions for function default parameters (formal parameter angle)
2022-06-25 16:09:00 【creedcc】
# Parameter angle , When the default parameter is a variable data type , Need attention
# If the default parameter points to a variable data type , No matter how many times this default parameter is called , All point to the same
# Create a new memory in the memory to store the list , Does not end with function , Memory disappears ( Here's the picture )
def func(name, lis=[]):
lis.append(name)
return lis
print(func('hello')) # ['hello']
print(func('ait')) # ['hello', 'ait']
def func1(num, l=[]):
l.append(num)
return l
print(func1(15)) # 15
print(func1(17, [])) # 17
print(func1(20)) # [15, 20]
def func2(num, l=[]):
l.append(num)
return l
ret1 = func2(15)
ret2 = func2(17, [])
ret3 = func2(20)
print(ret1) # [15, 20]
print(ret2) # 17
print(ret3) # [15, 20]
The memory space with variable data type as the default parameter will not disappear with the end of the function , Here's the picture .
边栏推荐
- Overall MySQL architecture and statement execution process
- 一文带你搞懂 JWT 常见概念 & 优缺点
- Classic deadlock scenario of multithreading and its solution (philosopher dining problem)
- 不要小看了积分商城,它的作用可以很大!
- Continuously improve the overall performance of adaoracle Oracle Oracle
- 《睡眠公式》:怎么治睡不好?
- B站付费视频使up主掉粉过万
- Mixed density network (MDN) for multiple regression explanation and code example
- Linux-MySQL数据库之高级SQL 语句一
- GO语言-锁操作
猜你喜欢

error Parsing error: Unexpected reserved word ‘await‘.
How to debug grpc by postman

商城风格也可以很多变,DIY 了解一下!

Lecun predicts AgI: big model and reinforcement learning are both ramps! My "world model" is the new way
Take you to the open source project of smart home: the preliminary configuration of zhiting home cloud and home assistant+ homebridge

GO语言-什么是临界资源安全问题?

《睡眠公式》:怎么治睡不好?

异步处理容易出错的点

教务系统开发(PHP+MySQL)

Optimization of lazyagg query rewriting in parsing data warehouse
随机推荐
Based on neural tag search, the multilingual abstracts of zero samples of Chinese Academy of Sciences and Microsoft Asiatic research were selected into ACL 2022
What are the reasons why the game industry needs high defense servers?
Problems caused by using ApplicationContext to render layout
Time wheel and implementation analysis of time wheel in go zero
Once the code was encrypted by the company's computer, the compilation failed
GO语言-锁操作
JS add custom attributes to elements
Linux-MySQL数据库之高级SQL 语句一
Uncover gaussdb (for redis): comprehensive comparison of CODIS
商城风格也可以很多变,DIY 了解一下!
Differences between = = and = = = in JS (detailed explanation)
Load local cifar10 dataset
Mt60b1g16hc-48b:a micron memory particles FBGA code d8bnk[easy to understand]
不要小看了积分商城,它的作用可以很大!
The database records are read through the system time under the Android system, causing the problem of incomplete Reading Records!
DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection翻译
[Third Party framework] retrofit2 (2) - add point configuration of network access framework
Inter thread synchronization semaphore control
Servlet details
The textfield is encapsulated by the flutter itself, which causes the data display to be disordered when the data in the list is updated.