If else can be represented by a simple ternary operator
If 1 = = 1: name = ' Wupeiqi ' else: name = ' Alex '
--》
name = ' Wupeiqi ' if 1 = = 1 Else ' Alex '
Lambda can also be used to simplify expressions for functions
# ###################### normal function ####################### definition function (normal way) def func (Arg): return arg + 1 # Execute function result = Func (123) # ###################### Lambda ###################### # definition function (lambda expression) My_lambda = lambda Arg:arg + 1 # Execute function Res Ult = MY_LAMBDA (123)
Built-in function 1,map
Iterates through the sequence, operates on each element of the sequence, and finally gets a new sequence.
Li = [one, one, 33]new_list1 = map (lambda a:a + li) Print new_list1
[111, 122, 133]
Li = [one, 33]SL = [1, 2, 3]new_list = map (lambda A, b:2*a + B, Li, SL) Print New_list
[23, 46, 69]
2,filter
Filter the elements in a sequence, and finally get a sequence that matches the criteria
Li = [one, one, 33]new_list2 = filter (lambda arg:arg >=, li) print new_list2
[22, 33]
3,reduce
Cumulative operation for all elements within a sequence
Li = [one, 33]SL = [1, 2, 3]result = reduce (lambda arg1, Arg2:arg1 + arg2, li) print result
# Reduce the first argument, the function must have two parameters # reduce the second parameter, to loop the sequence # reduce the third parameter, the initial value
66
Python's lambda