Answers for "get class python"

1

how to get name of class in class python

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
Posted by: Guest on March-27-2020
1

python get object class

user = User()
type(user).__name__
>> 'User'
Posted by: Guest on May-07-2021

Python Answers by Framework

Browse Popular Code Answers by Language