面向对象---》对象------》Class
面向过程---》过程------》def
函数式编程---》函数----》def
函数的介绍:
def fun1():
'''the function instruction'''
x-=1
return x
def fib(n):
"""Print a Fibconacci series up to n""" #对此函数的解释说明
a,b = 0,1
while a<
n:
print(a,end=
' ')
a,b=b,a+
b
print()
fib(2000
)
#结果
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
函数与过程的区别: 函数有返回值, 过程无返回值
#函数
def func1():
"""test1"""
print(
"It's func1")
return 1
#过程
def func2():
"""test2"""
print(
"It's func2")
func1()
func2()
print(
"----------------")
print(func1())
print(func2())
#测试结果:
It
's func1
It
's func2
----------------
It's func1
1
It's func2
None
转载于:https://www.cnblogs.com/frankb/p/6218850.html