SelfCount/danilkonon1239
SelfCount/FrBrGeorge
n1"""n1#!/usr/bin/env python3
2 2'''
3Счётчик экземпляров3'''
4Написать класс WeAre, экземпляры которого содержат поле count.
5В этом поле хранится количество существующих экземпляров этого класса.
6 
7Примеры
8Входные данные
9a = WeAre()
10print(a.count)
11b, c = WeAre(), WeAre(),
12print(a.count, b.count, c.count)
13del b
14print(a.count)
15Результат работы
161
173 3 3
182
19 
20 
21"""
224
235
24class WeAre:6class WeAre:
25    count = 07    count = 0
268
27    def __init__(self):9    def __init__(self):
n28        self.__class__.count += 1n10        type(self).count += 1
2911
30    def __del__(self):12    def __del__(self):
n31        self.__class__.count -= 1n13        type(self).count -= 1
3214
t33 t
34# a = WeAre()
35# print(a.count)
36# b, c = WeAre(), WeAre(),
37# print(a.count, b.count, c.count)
38# del b
39# print(a.count)
40 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op