python内置函数均值 python内置函数含义( 二 )


如果函数没有return关键字,则函数默认返回None# 形参和实参的案例
# 参数person只是一个符号
# 调用的时候用另一个
def hello(person):
print("{},你好吗?".format(person))
return None
p = "小明"
# 调用函数,需要把p作为实参传入
hello(p)小明,你好吗?p = "小五"
hello(p)小五,你好吗?pp = hello("小柒")
print(pp)小柒,你好吗?
None# return案例
def hello(person):
print("{0},你好吗?".format(person))
return "提前结束!"
print(1)
p = "小明"
rst = hello(p)
print(rst)小明,你好吗?
提前结束!# help负责随时为你提供帮助
help(None) # 等价于help(peint())Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.# 九九乘法表
# version 1.0
for o in range(1, 10): # 控制外循环 从 1 到 9
for i in range(1, o + 1): # 内循环,每次从第一个数字开始,打印到跟行数相同的数量
print(o * i, end=" ")
print()1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81help(print)Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.# 尝试用函数来打印九九乘法表
def jiujiu():
for o in range(1, 10): # 控制外循环 从 1 到 9
for i in range(1, o + 1): # 内循环,每次从第一个数字开始,打印到跟行数相同的数量
print(o * i, end=" ")
print()
return None
jiujiu()
jiujiu()1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81# 改造上面函数
def printLine(line_num):
'''
line_num;代表行号
打印一行九九乘法表
'''
for i in range(1, line_num + 1):
print(line_num * i, end=" ")
print()
def jiujiu():
for o in range(1, 10): # 控制外循环 从 1 到 9
printLine(o)
return None
jiujiu()1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
参数详解python参考资料:headfirst python - 零基础入门学习python(小甲鱼)、流畅的python - 习题
参数分类普通参数/位置参数
默认参数
关键字参数
收集参数
普通参数c参见上例
定义的时候直接定义变量名
调用的时候直接把变量或者值放入指定位置def 函数名(参数1,参数2,.....):
函数体
# 调用
函数名(value1,value2,......)
# 调用的时候,具体值参考的是位置,按位置赋值
默认参数形参带有默认值

推荐阅读