day_4_25 py

''' 
Recursion:
If a function does not call other functions internally,
but itself, this function is a recursive function
'''
def factor(num):
if num >1:
result = num*factor(num-1 )
else:
result =1
return result
ret = factor(3)
print(ret)

'''
Anonymous function:
Use the lambda keyword to create small anonymous functions.
This kind of function gets its name from omitting the standard step of declaring a function with def

lambda [arg1 [,arg2,.....argn]]:expression
''' #is
a function without the keyword def
'''
anonymous function expansion
'''
def fun(a,b,opt):
print("a=",a)
print("b=",b)
print("result=",opt)
fun(1,2,lambda x,y :



{"name":"lisi", "age":19},
{"name":"wangwu", "age":17}
]
# Sort by name
stus.sort(key = lambda x:x['name' ])
print(stus)
# Sort by age
stus.sort(key = lambda x:x['age'])
print(stus)
'''
Exchange of two variables
'''
a = 4
b = 5
# # The first one
# c = 0
# c = a
# a = b
# b = c
# # second
# a = a+b
# b = ab
# a = ab
# third
a,b = b,a
print( "a=%d,b=%d"%(a,b))
'''
document knowledge explanation
'''

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324879792&siteId=291194637