object oriented programming python code example
Example 1: class and object in python
class PartyAnimal:
def Party():
an=PartyAnimal()
an.Party()
Example 2: oop in python
class Object:
def __init__(self,arg):
self.arg = arg
def printArg(self):
print(self.arg)
Example 3: real python oop
>>> class Dog:
... pass
...
>>> a = Dog()
>>> type(a)
<class '__main__.Dog'>
Example 4: python how to use oop
class Dog:
def __init__(self, name):
self.name = name
def get_name(self):
return self.name
if __name__ == "__main__":
d = Dog(str(input("name your dog: "))
print(d.get_name())