advanced python 3 cheat sheet pdf code example
Example 1: python generator cheat sheet download
def get_multiplier(a):
def out(b):
return a * b
return out
Example 2: python generator cheat sheet download
class <name>:
def __init__(self, a):
self.a = a
def __repr__(self):
class_name = self.__class__.__name__
return f'{class_name}({self.a!r})'
def __str__(self):
return str(self.a)
@classmethod
def get_class_name(cls):
return cls.__name__
Example 3: python generator cheat sheet download
from functools import wraps
def debug(func):
@wraps(func)
def out(*args, **kwargs):
print(func.__name__)
return func(*args, **kwargs)
return out
@debug
def add(x, y):
return x + y