Python Day6
Yixin Lv4

函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 函数
# 函数是可重复调用的代码段,能提高代码的复用率。

# 无参数
def print_hello():
print ("hello")


print_hello()


# 带参数
def print_str(s):
print(s)
return s * 2


print_str("fuck")


# 带默认参数
def print_default(s="hello"):
print(s)


print_default()
print_default("default")


# 不定长参数
def print_args(s, *arg):
print(s)
for a in arg:
print(a)
return


print_args("hello")
print_args("hello", "world", "1")


# 参数次序可以变
def print_two(a, b):
print(a, b)


print_two(a="a", b="b")
print_two(b="b", a="a")
  • Post title:Python Day6
  • Post author:Yixin
  • Create time:2021-05-02 15:17:21
  • Post link:https://keep.xpoet.cn/2021/05/02/simpread-Python 学习 -Day6(2021.3.3)_Yixin 的博客 - CSDN 博客/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments