1class test:
2 @property
3 def cls_name(self):
4 return self.__class__.__name__
5
6 @property
7 def cls_name_2(self):
8 return type(self).__name__
9
10 @classmethod
11 def cls_name_3(cls):
12 return cls.__name__
13
14ins = test()
15
16print(ins.cls_name)
17print(ins.cls_name_2)
18print(ins.cls_name_3())
1class SillyClassName:
2 @classmethod
3 def my_name(cls_):
4 return cls_.__name__
5
6 def class_name(self):
7 # self.__class__ gets the current class
8 # .__name__ gets the name
9 return self.__class__.__name__
10
11SillyClassName.my_name()
12# prints SillyClassName
13
14inst = SillyClassName()
15inst.class_name()
16# prints SillyClassName