当前位置:网站首页>Section 4 of Chapter 3: formal parameters
Section 4 of Chapter 3: formal parameters
2022-07-22 09:50:00 【Zhongyifeng Digital Technology Co., Ltd】
Python Basic introduction ( A full set of nanny level tutorials )
The third chapter
The fourth quarter, : Shape parameter
Shape parameter
Positional arguments
At the time of function definition . Some variables need to be prepared to receive information
def luru(name, age, gender=" male "):
print(name, age, gender)
luru(" Zhang San ", 18)
luru(" Li Si ", 28)
luru(" Wang two pock marks ", 38)
luru(" Wu Laoer ", 14)
luru(" Zhao Min ", 12, " Woman ")
luru(" Zhou Zhiruo ", 11, " Woman ")
Dynamic transfer parameters
def chi(*food): # * Represents the dynamic transfer of position parameters , * The received values will be uniformly placed in a tuple
print(food)
chi(' Rice ', " Braised eggplant ", ' Seaweed and Egg Soup ', " Haagen-Dazs ")
chi(" Rice ")
chi(" Rice ", " Braised eggplant ")
chi(" Rice ", " Seaweed and Egg Soup ")
chi(" Rice ", " Seaweed and Egg Soup ", " Seaweed and Egg Soup ")
Dynamic parameters of keywords
def chi(**food): # ** Indicates the dynamic parameter transmission of the received keyword , All parameters received will be processed into a dictionary
print(food)
chi(fu=" Muxu persimmon ", zhu=" Little rice ")
Receive any parameters without restrictions
def func(*args, **kwargs): # Receive any parameters without restrictions
print(args, kwargs)
func() # (), {}
func(1) # (1, ), {}
func(1,2,3,4,4, a=2) # (1,2,3,4,4), {"a":2}
func(1,2,3,4, c=4, a=2)# (1,2,3,4), {"c":4, "a":2}
summary :
Shape parameter , At the time of function definition . Some variables need to be prepared to receive information
1. Positional arguments , Declare variables one by one according to position
2. Default parameter , Give the variable a default value when the function is declared , If the argument does not pass information . At this time, the default value takes effect , Otherwise, it will not take effect
3. Dynamic transfer parameters .
1. *args, Indicates the dynamic transmission of all position parameters
2. **kwargs, It means to receive dynamic parameters of all keywordsThe order *: Location > *args > The default value is > **kwargs
边栏推荐
- 36.删除链表的倒数第 N 个结点
- Responsive layout - font common units
- [Datasheet] PHY LAN8720网络芯片解读
- Biochemistry review IV. lipids
- Oracle error list
- Kotlin basic grammar
- Animate the box in the middle and 100px to the left and right of the browser
- Section 1 of Chapter 3: concept of function
- 第二章第二十二节:文件操作1
- ConstraintLayout从0到0.n学习
猜你喜欢
随机推荐
Biochemistry review II. Nucleic acid
28.接雨水
Oracle error list
Responsive layout - Mobile Web pixels
关于IE6浏览器出现的问题的解决
Section 20 of Chapter 2: operators one
Comment win10 envoie une icône au Bureau
贝加莱使用教程1-创建X20工程和点亮LED灯
Applet output console
微信小程序Text限定行数
32.二叉树中的最大路径和
微信小程序自适应性的自定义导航栏开发
第二章 第二十四节:文件操作:写
关于包装对象
Life cycle of Servlet
Tuples, lists, sets, and some notes on exception handling
列表迭代器
Biochemistry review IV. lipids
无套路、无陷阱、无广告 | 这个免费的即时通讯软件确定不用吗?
30.重排链表