Skip to content

Commit feb8758

Browse files
authored
函数参数的练习以及最后的作业
1 parent 55ce7f8 commit feb8758

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 练习python的参数
2+
3+
# 命名关键字参数,与默认参数有点不同,这个参数没有默认值,而且也属于必填参数,不填时会报错
4+
def fun(name,age,*,city,job):
5+
print(name,age,city,job)
6+
7+
fun('huang',15,city='biejing',job='progrommer')
8+
9+
10+
11+
# 参数下的练习题
12+
def product(*nums):
13+
if nums is None:
14+
raise TypeError('参数不能为None')
15+
res = 1
16+
for num in nums:
17+
res *= num
18+
19+
return res

0 commit comments

Comments
 (0)