简介
在 Python 中,函数是一等公民,这意味着它们可以像任何其他值一样被传递。这种特性的一个有用应用是根据某个谓词有条件地将一个函数应用于一个值。在这个挑战中,你将被要求编写一个函数,它接受一个谓词函数和一个在谓词为真时要应用的函数,并返回一个新函数,该新函数在谓词为真时应用该函数。
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
python(("Python")) -.-> python/DataStructuresGroup(["Data Structures"])
python(("Python")) -.-> python/FunctionsGroup(["Functions"])
python(("Python")) -.-> python/BasicConceptsGroup(["Basic Concepts"])
python(("Python")) -.-> python/ControlFlowGroup(["Control Flow"])
python/BasicConceptsGroup -.-> python/comments("Comments")
python/ControlFlowGroup -.-> python/conditional_statements("Conditional Statements")
python/DataStructuresGroup -.-> python/tuples("Tuples")
python/FunctionsGroup -.-> python/function_definition("Function Definition")
python/FunctionsGroup -.-> python/lambda_functions("Lambda Functions")
subgraph Lab Skills
python/comments -.-> lab-13742{{"有条件地应用函数"}}
python/conditional_statements -.-> lab-13742{{"有条件地应用函数"}}
python/tuples -.-> lab-13742{{"有条件地应用函数"}}
python/function_definition -.-> lab-13742{{"有条件地应用函数"}}
python/lambda_functions -.-> lab-13742{{"有条件地应用函数"}}
end