python第十四课--排序及自定义函数之自定义函数(案例四)


整理:4中最常见的自定义函数模型
1).无参无返回值
2).无参有返回值
3).有参无返回值
4).有参有返回值
#定义无参无返回值自定义函数
def func1():
    print('hello method...')


#定义无参有返回值自定义函数
def func2():
    return True

#定义有参无返回值自定义函数
def func3(a,b):
    print(a+b)

#定义有参有返回值自定义函数
def func4(a,b):
    # func(a,b)
    return a if a>b else b

maxNum=func4(10,1000)
print('较大值为:'+str(maxNum))

func1()
func2()
func3(10,20)
func4(10,100)

猜你喜欢

转载自www.cnblogs.com/hankleo/p/10432676.html