Adam Wuerl
0
Q:

python class name

type(x).__name__
4
class SillyClassName:
    @classmethod 
	def my_name(cls_):
		return cls_.__name__

 def class_name(self):
  	# self.__class__ gets the current class
    # .__name__ gets the name
	return self.__class__.__name__

SillyClassName.my_name()
# prints SillyClassName

inst = SillyClassName()
inst.class_name()
# prints SillyClassName
0
instance.__class__.__name__
0
>>> class Complex:
...     def __init__(self, realpart, imagpart):
...         self.r = realpart
...         self.i = imagpart
...
>>> x = Complex(3.0, -4.5)
>>> x.r, x.i
(3.0, -4.5)
-2

New to Communities?

Join the community