to execute other functions. it actually calls the function we pass in as argument def execute(f): f() applying def print_these(): print('----') print('....') print('----') execute(print_these) # same as print_these() # ---- # .... # ----
---- # > <<the sun is rising>> # ---- we just add another function def enclose(f): def dummy(text): return '----\n{}\n----'.format( f(text) ) return dummy and just call @enclose
class import math class Calcs: def add(self, x, y): return x + y def hypotenuse(self, x, y): return math.sqrt((x**2) + (y**2)) c = Calcs() print(c.hypotenuse(3, 4)) # 5.0 functions not related together
class Calcs: @staticmethod def add(x, y): return x + y def hypotenuse(self, x, y): return math.sqrt((x**2) + (y**2)) c = Calcs() print(c.add(1, 2)) # 3 isolated from class, using another method/var results in error