1、面向对象,类(class);2、面向过程,过程(def);3、函数式编程,函数(def)
def func1():
print(“in the func1”)
…….
…….
return 0
传递不定量的参数时,形参使用*的形式,参数会作为一个元组进入
def test(*a):#元组,接受N个位置参数,转换成元组的形式
print(a)
test (1,2,3,4,5)
test (*[1,2,3,4,5])#列表
def test2(**a)#把n个关键字参数转化成字典形式
print(a[‘name’])
print(a)
test2(name=’alex’,age=23,sex=’nan’)
test2(**{‘name’:’alex’,’age’:’23’})
def test3(name,**a): #参数组放最后
print(name)
print(a)
test(‘alex’)
test(‘alex’,age=23,sex=’F’)
递归:通过栈的数据结构实现,太多会栈溢出
def calc(n):#最大999层
print(n)
return calc(n+1)
calc(0)