class name in python code example
Example 1: python get type class name
type(x).__name__
Example 2: python class
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name +".")
p1 = Person("Victor", 24)
p1.myfunc()
Example 3: how to make a class in python
class Person:
def __init__(self, _name, _age):
self.name = _name
self.age = _age
def sayHi(self):
print('Hello, my name is ' + self.name + ' and I am ' + self.age + ' years old!')
p1 = Person('Bob', 25)
p1.sayHi()
Example 4: python class name
instance.__class__.__name__
Example 5: how to get name of class in class python
class SillyClassName:
@classmethod
def my_name(cls_):
return cls_.__name__
def class_name(self):
return self.__class__.__name__
SillyClassName.my_name()
inst = SillyClassName()
inst.class_name()
Example 6: python class
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
p1 = Person("barry", 50)
p1.myfunc()