python program to create class and object code example
Example 1: 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 2: class and object in python
class PartyAnimal:
def Party():
an=PartyAnimal()
an.Party()
Example 3: class python example
def ok(index):
print(index) > Hi!
ok("Hi!")
class Lib:
def ok(self,Token):
print(Token) > Hello World!
Library = Lib()
Library.ok("Hello World!")
Example 4: how to define a class in python
class a_class:
def __init__(self, input1):
self.__input1 = input1
def return_input(self):
return self.__input1
a_class_object = a_class("input string")
print(a_class_object.return_input())