You can not select more than 25 topics
Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- # define a higher order function
- # note: this function receives a function as an argument
- def apply_twice(func, x):
- # note: this function returns a function
- return func(func(x))
-
- # define a simple function
- def square(x):
- return x * x
-
- # use this higher order function
- result = apply_twice(square, 2)
- print(result) # output: 16
|