1>>> permutations('abc', 2) # a b c
2[('a', 'b'), ('a', 'c'), # a . x x
3 ('b', 'a'), ('b', 'c'), # b x . x
4 ('c', 'a'), ('c', 'b')] # c x x .
5
1class <name>:
2 def __init__(self, a):
3 self.a = a
4 def __repr__(self):
5 class_name = self.__class__.__name__
6 return f'{class_name}({self.a!r})'
7 def __str__(self):
8 return str(self.a)
9
10 @classmethod
11 def get_class_name(cls):
12 return cls.__name__
13
1>>> counter = count(10, 2)
2>>> next(counter), next(counter), next(counter)
3(10, 12, 14)
4
1from functools import wraps
2
3def debug(print_result=False):
4 def decorator(func):
5 @wraps(func)
6 def out(*args, **kwargs):
7 result = func(*args, **kwargs)
8 print(func.__name__, result if print_result else '')
9 return result
10 return out
11 return decorator
12
13@debug(print_result=True)
14def add(x, y):
15 return x + y
16
1>>> combinations_with_replacement('abc', 2) # a b c
2[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x
3 ('b', 'b'), ('b', 'c'), # b . x x
4 ('c', 'c')] # c . . x
5
1class Person:
2 def __init__(self, name, age):
3 self.name = name
4 self.age = age
5
6class Employee(Person):
7 def __init__(self, name, age, staff_num):
8 super().__init__(name, age)
9 self.staff_num = staff_num
10
1from functools import wraps
2
3def debug(func):
4 @wraps(func)
5 def out(*args, **kwargs):
6 print(func.__name__)
7 return func(*args, **kwargs)
8 return out
9
10@debug
11def add(x, y):
12 return x + y
13