1、python自定义函数(一般用def来定义)
#第一种方式
def Sum(x,y):
return x+y
#第二种方式
y=lambda x:x**2
y1=lambda x:x[1]
res=Sum(1,2)#调用函数 3
res=y(10)# 100
res=y1(['hello',13])# 13
2、面向对象
class Human:
def __init__(self,ag=None,se=None):
self.age=ag #属性
self.sex=se
def square(self,x):
return x**2 #方法
zhangfei=Human(ag=23,se='男')#类的实例化
res=zhangfei.square(10)
res=zhangfei.age
res=zhangfei.sex